FastPrepCollatz Conjecture with Shared Memoization
Problems/Collatz Conjecture with Shared Memoization

Collatz Conjecture with Shared Memoization

Bloomberg LP logoBloomberg LP● MediumNEW GRADFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in multiple first-hand Bloomberg new-grad phone and onsite interviews. The batch contract exposes the source's memoization follow-up by sharing cached intermediate step counts across queries.

You are given a list of numbers, queries. For each one, return its Collatz step count, written as a decimal string.

To count the steps for a positive number n, keep changing it with these rules:

  • If n is even, replace it with n / 2.
  • If n is odd, replace it with 3n + 1.

The step count is how many replacements it takes to reach 1. If a query is zero or negative, return "null" for it.

Answer the queries in order. Save every step count you work out, including the counts for the values you pass through on the way, and reuse them for all later queries.

Function

collatzSteps(queries: long[]) → String[]

Examples

Example 1

queries = [5,8,4,-3]return = ["5","3","2","null"]

The first query follows 5 -> 16 -> 8 -> 4 -> 2 -> 1, which is five steps. The next two queries are values already on that path, so their saved counts are reused: three steps and two steps. The last query is negative, so its answer is null.

Example 2

queries = [1,2,3]return = ["0","1","7"]

One is already the target, so it takes zero steps. Two takes one step. Three follows 3,10,5,16,8,4,2,1, which is seven steps.

Constraints

  • 1 <= queries.length <= 10^4.
  • -10^6 <= queries[i] <= 10^6.
  • For positive queries in the range above, every value along the way fits in a signed 64-bit integer.

More Bloomberg LP Phone Screen questions

  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
  • Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
  • Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Financial Account LedgerStripe · OA · PHONE SCREENStripe interview questions
  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
  • Mutable Points in a Hash Set and a ListMillennium · PHONE SCREENMillennium interview questions
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Order and Batch Open-Close LifecycleHudson River Trading · PHONE SCREENHudson River Trading interview questions
  • Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions

Interview reports that mention this question

  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
  • Bloomberg New Grad Question Bank: 161 Questions (Part 1 of 2)
  • Bloomberg New Grad Screens: 30 Experiences (Part 4 of 5)
  • Bloomberg New Grad OOD Follow-ups: 14 Experiences (Part 3 of 5)

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public String[] collatzSteps(long[] queries) {
      // Write your code here.
    }
}
Checking account…