Find Beautiful Indices in the Given Array II
A hard-tier problem at 26% community acceptance, tagged with Two Pointers, String, Binary Search. Reported in interviews at Palantir Technologies and 1 others.
Find Beautiful Indices in the Given Array II is a hard problem that landed on Palantir and PhonePe assessments. The 26% acceptance rate tells you this isn't a standard two-pointer drill. The problem chains string matching with constraint-based filtering, forcing you to manage substring locations across two patterns simultaneously. If you blank on the indexing logic or mishandle the distance constraint during a live OA, StealthCoder solves it invisibly in seconds. You need the pattern recognition fast.
Companies that ask "Find Beautiful Indices in the Given Array II"
Find Beautiful Indices in the Given Array II is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe trick is recognizing this as a two-step string matching problem with a spatial filter. You find all occurrences of two patterns in a string, then return indices from one pattern whose closest match in the other pattern falls within a given distance. The naive approach flattens, wastes CPU on every pair comparison, and blows up on large inputs. Binary search cuts the search space for nearest neighbors dramatically. Rolling hash or KMP accelerates pattern matching. The hard part isn't any single technique; it's stitching them together without off-by-one errors in the distance check. Most candidates stall on either the string matching choice or the constraint logic. StealthCoder hedges the moment you hit this in your assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Find Beautiful Indices in the Given Array II recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find Beautiful Indices in the Given Array II interview FAQ
Is this problem really as hard as the 26% pass rate suggests?+
Yes. The multi-step nature (find matches, filter by distance) trips up engineers who've only drilled basic two-pointer or string matching. You can't brute force the pairs without TLE. Binary search becomes mandatory once you understand the pattern.
Do I need Rolling Hash, or can I use built-in string matching?+
Built-in functions work, but Rolling Hash (the explicit topic here) scales better and is expected at Palantir. It's not optional context; it's part of the problem's design. Know both KMP and rolling hash before the OA.
What's the biggest pitfall when coding this live?+
Off-by-one errors in the distance constraint and mismanaging the indices of closest matches. Many candidates get the string matching right but fail the binary search boundary logic. Trace the distance formula carefully before you submit.
How does Binary Search fit into this problem?+
After finding all pattern matches, you use binary search on sorted match lists to find the nearest index in pattern two for each index in pattern one. It reduces the pair-comparison from O(n*m) to O(n log m), which is the only way to pass large inputs.
Will Palantir or PhonePe ask follow-up questions if I solve this?+
Almost certainly. They'll probe your understanding of hash collisions, why rolling hash is better than naive string search, or ask you to optimize further. Be ready to explain every choice, not just the code.
Want the actual problem statement? View "Find Beautiful Indices in the Given Array II" on LeetCode →