Fibonacci Term Index
Updated
Problem statement
The Fibonacci sequence starts 1, 1, 2, 3, 5, 8, 13, .... Each term after the first two is the sum of the two terms before it. Terms are numbered from 1, so term 1 is 1, term 2 is 1, term 3 is 2, and term 6 is 8.
You are given an array queries of numbers. For each number, return its term number. The number 1 is both term 1 and term 2, so report the first one, term 1. If a number is not in the sequence, return -1.
Return an array with one answer for each query, in the same order. Many queries are asked in one call, so work you have already done can be reused.
Function
fibonacciPositions(queries: int[]) → int[]Examples
Example 1
queries = [5,8,4]return = [5,6,-1]The sequence starts 1, 1, 2, 3, 5, 8, .... The number 5 is term 5 and the number 8 is term 6.
The number 4 is not in the sequence (it falls between 3 and 5), so its answer is -1.
Example 2
queries = [1,2,3]return = [1,3,4]The number 1 appears twice, as term 1 and as term 2. Report the first one, term 1.
The number 2 is term 3 and the number 3 is term 4.
Example 3
queries = [21,22,34,34]return = [8,-1,9,9]21 is term 8, 22 is not in the sequence, and 34 is term 9. The same number can be asked twice, and it gets the same answer both times.
Example 4
queries = [1836311903,1836311904,2000000000]return = [46,-1,-1]1836311903 is term 46, the last term that is at most 2000000000. The next number, 1836311904, and 2000000000 are not terms, so they give -1.
Constraints
1 <= queries.length <= 50001 <= queries[i] <= 2 * 10^9
More Bloomberg LP Onsite Interview questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Majority ElementMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Count Index Pairs with Equal Value OffsetGoogle · ONSITE INTERVIEWGoogle interview questions
- Net Position Calculation from API SnapshotsHeadlands Technologies · ONSITE INTERVIEWHeadlands Technologies interview questions
- Square Each Array ValueAMD · ONSITE INTERVIEWAMD interview questions
- Max Points on a LineLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Integers With Multiple Sum of Two CubesCharta Health · PHONE SCREEN · ONSITE INTERVIEWCharta Health interview questions
- Fractional Share Inventory FlatteningRobinhood · PHONE SCREEN · ONSITE INTERVIEWRobinhood interview questions
- Group-Relative Policy AdvantagesAmazon · ONSITE INTERVIEW
- Product Total With the Cheapest PromotionInstacart · ONSITE INTERVIEWInstacart interview questions
- Count Divisible Power SumsGoodScore · ONSITE INTERVIEW
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)