Starting Value with the Longest Collatz Chain
Updated
Problem statement
For a positive value n, repeatedly replace an even value by n / 2 and an odd value by 3n + 1 until reaching 1.
Among starting values from 1 through limit, return the one with the longest chain, counting both the start and 1. Break equal lengths by the smaller starting value.
Function
longestCollatzStart(limit: int) → intExamples
Example 1
limit = 1return = 1Only starting value one is available.
Example 2
limit = 2return = 2Two has a longer chain than one.
Constraints
1 <= limit <= 1000000- Intermediate values fit in signed 64-bit integers.
More ZipRecruiter Phone Screen questions
- Neighboring Record IDsPHONE SCREEN · Seen May 2026
- Restaurant Vote LeadersPHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
- Most Frequent Word across Grouped ArraysPHONE SCREEN · Seen Sep 2024
- Classify an Alien Dictionary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2022
- Multiset Intersection of Three ListsPHONE SCREEN · Seen Feb 2022
- Find the Smallest Magic IndexPHONE SCREEN · Seen Dec 2021
- Website Pair with the Most Common VisitorsPHONE SCREEN · Seen Nov 2021
- Center-Outward Number SpiralPHONE SCREEN · Seen Jun 2021
- Missing Ranges within Inclusive BoundsPHONE SCREEN · Seen Feb 2021
- Fibonacci Number with Constant Extra SpacePHONE SCREEN · Seen Mar 2017
Similar questions at other companies
- Dice-Walk Winning ProbabilityGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- 3D Grid Diagonal Walk ProbabilityApple · PHONE SCREENApple interview questions
- Coin Game From The EndsTekion · PHONE SCREENTekion interview questions
- Highest Die Roll WinsJane Street · PHONE SCREENJane Street interview questions
- Median of Uniform Draws in an IntervalSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
- Count Array DerangementsInMobi · PHONE SCREENInMobi interview questions
- Maximum-Product Subarray with an Empty ChoiceAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Count Staircase WaysGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- New 21 Game ProbabilityUiPath · PHONE SCREEN