Streaming Palindrome Checker
Updated
Problem statement
Process an append-only stream of lowercase characters. The stream starts empty, and each row of operations is one of:
["track", character]: append the one-character stringcharacterto the stream.["isPalindrome"]: report whether the entire stream currently reads the same forward and backward.
Return the boolean answers to the isPalindrome operations in encounter order. The empty stream is a palindrome.
Each isPalindrome query must run in O(1) time. The complete operation sequence must be processed exactly, without probabilistic hashing.
Function
streamPalindrome(operations: String[][]) → boolean[]Examples
Example 1
operations = [["track","a"],["track","b"],["track","c"],["track","b"],["track","a"],["isPalindrome"]]return = [true]The tracked stream is abcba, which is a palindrome.
Example 2
operations = [["isPalindrome"],["track","a"],["isPalindrome"],["track","b"],["isPalindrome"],["track","a"],["isPalindrome"]]return = [true,true,false,true]The queried streams are empty, a, ab, and aba.
Example 3
operations = [["track","a"],["track","b"],["track","b"],["isPalindrome"],["track","a"],["isPalindrome"],["track","c"],["isPalindrome"]]return = [false,true,false]The queried streams are abb, abba, and abbac.
Constraints
1 <= operations.length <= 200000.- Every row is exactly
["track", character]or["isPalindrome"]. - Every tracked
characteris one lowercase English letter. - At least one
isPalindromeoperation occurs.
More Bloomberg LP Onsite Interview questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 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
- 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
Similar questions at other companies
- Recover a Tree From Preorder TraversalGrammarly · PHONE SCREEN · ONSITE INTERVIEW
- Parse Boolean Rule ExpressionsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Serialize and Deserialize a Binary TreeAmazon · ONSITE INTERVIEW
- Minimum Insertion Steps to Make a String PalindromeInfosys · ONSITE INTERVIEWInfosys interview questions
- Wildcard MatchingTripjack · ONSITE INTERVIEWTripjack interview questions
- Alien DictionaryByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- All Balanced Strings from Minimum Parenthesis InsertionsRubrik · ONSITE INTERVIEWRubrik interview questions
- Design Search Autocomplete SystemRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Longest Duplicate SubstringGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions