Self-Describing Indices in Pi Digits
Updated
Problem statement
A string digits contains a sequence of decimal digits. The interview scenario uses a prefix of the digits of pi after the decimal point. Positions are one-based.
An index i is self-describing when the digits used to write i exactly match the part of the input ending at position i. If i has d digits, compare it with positions i - d + 1 through i. Positions before 1 cannot match.
Return every self-describing index in increasing order.
Function
findSelfDescribingIndices(digits: String) → int[]Examples
Example 1
digits = "123456789"return = [1,2,3,4,5,6,7,8,9]At every one-digit position, the stored digit equals that index.
Example 2
digits = "000000000012"return = [12]Positions 11 and 12 form 12, so index 12 matches.
Example 3
digits = "1204"return = [1,2,4]Indices one, two, and four match their one-character suffixes.
Constraints
1 <= digits.length <= 1000000.digitscontains only characters'0'through'9'.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Container Ledger with TradesFlexport · ONSITE INTERVIEWFlexport interview questions
- Christmas Tree with N TiersVerily · ONSITE INTERVIEW
- Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
- Document Edit EventsClickUp · ONSITE INTERVIEW
- Predict Runtime Method DispatchAMD · ONSITE INTERVIEWAMD interview questions
- Basic String Compression with Length GuardNew Relic · PHONE SCREEN · ONSITE INTERVIEW
- Print Sentences as TableAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
- Retry with an Attempt LimitOracle · ONSITE INTERVIEWOracle interview questions
- Extract Error Log ContextFlexTrade · ONSITE INTERVIEWFlexTrade interview questions
- Run-Length Encode Consecutive Letter RunsMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions