Get Minimum Operations
Updated
Problem statement
Starting from 0, add 1, then multiply by 2 three times. It takes a minimum of 4 operations to get to 8, so store 4 in index 0 of the return array.
Function
getMinOperations(kValues: int[]) → int[]
Complete the function getMinOperations in the editor with the following parameter(s):
kValues[n]: the values to match
Returns
int[n]: answers to a list of queries in the given order
- Constraints 1 ≤ n ≤ 10^4
- 0 ≤ kValues ≤ 10^16
Examples
Example 1
kValues = [5, 3]return = [4, 3]- To get from 0 to
kValues[0] = 5, ADD_1 → MULTIPLY_2 → MULTIPLY_2 → ADD_1 to get 0 + 1 → 1 × 2 → 2 × 2 → 4 + 1 = 5. Because it took four operations, store 4 in index 0 of the return array. - To get from 0 to
kValues[1] = 3, ADD_1 → MULTIPLY_2 → ADD_1 to get 0 + 1 → 1 × 2 → 2 + 1 = 3. Because it took three operations, store 3 in index 1 of the return array.
More JP Morgan Chase interview questions
- Longest Consecutive SequencePHONE SCREEN · Seen Nov 2026
- LFU CacheONSITE INTERVIEW · Seen Nov 2026
- LRU CacheONSITE INTERVIEW · Seen Nov 2026
- Find Total CostOA · Seen Oct 2026
- Minimum Meeting RoomsOA · Seen Oct 2026
- Count Dropped RequestsOA · Seen Oct 2026
- Maximize Binary XOR with a Set-Bit LimitPHONE SCREEN · Seen Oct 2026
- Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
- Task SchedulingOA · Seen Oct 2026
- Substring RemovalOA · Seen Oct 2026
Similar questions at other companies
- Minimum Operations To Reduce To ZeroUber · OAUber interview questions
- Integer BreakAmazon · ONSITE INTERVIEW
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
- Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Count Lucky TicketsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Task Scheduler with CooldownGoDaddy · OA
- Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
- Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
JP Morgan Chase interview experiences
- JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
- JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
- JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
- JP Morgan Chase Data and AI Intern Superday: 11 Experiences
- JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
- JPMorgan Code for Good India: 10 Experiences (Part 4 of 5)