Katkat

Compute min operations to transform integers

Akuna CapitalSoftware Engineer · Online Assessment

Last updated

This question evaluates algorithmic problem-solving skills related to integer transformations and reasoning about sequences of allowed operations, focusing on optimizing the number of steps. It is commonly used in the Coding & Algorithms domain to assess practical application of algorithmic thinking and time-complexity analysis, testing efficiency reasoning rather than purely conceptual knowledge.

Given integers A and B, transform A into B using the minimum number of operations. Allowed operations: (

  1. subtract 1 from the current value; (
  2. multiply the current value by 2. For each sample, determine the minimum number of operations and explain your approach and its time complexity: Sample 01: A = 1, B = 2; Sample 02: A = 9, B = 1; Sample 03: A = 2, B = 10; Sample 04: A = 100, B = 500.