Unique Elements After Modification
Reported by candidates from Infosys's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Infosys hit you with a classic array transformation problem in March. You're given an array, you modify elements according to some rule, then count or return the unique values. The trap is assuming the modification is straightforward. It usually involves a mathematical operation (doubling, incrementing, modular arithmetic) applied across the array, and you need to track uniqueness before or after the transformation. StealthCoder can read the exact modification rule off your screen and hand you the pattern in seconds if you freeze.
Pattern and pitfall
The core trick here is realizing that uniqueness checks happen on the transformed values, not the originals. Most candidates code a naive solution that modifies and counts in one pass, missing edge cases where two different inputs map to the same output. You'll likely need a hash set to track transformed values, then return the size or iterate through the set. The gotcha is the modification rule itself: read it twice. If it's something like 'add the value of the previous element' or 'multiply by index plus one,' off-by-one errors kill submissions. This is a hash-table and counting pattern that looks simple but punishes carelessness. If you blank on the exact transformation during the live OA, StealthCoder pulls the problem text and shows you the mechanic instantly.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Unique Elements After Modification cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Infosys's OA.
Infosys reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Unique Elements After Modification FAQ
Is this a hard problem or just finicky?+
Finicky. The algorithm is straightforward once you parse the modification rule correctly. Most failures come from misreading the transformation or not tracking state correctly across the array. Code carefully and test with the examples they give.
Do I need dynamic programming here?+
No. This is hash-table and iteration. You modify the array (or simulate modification), track unique values in a set, and return the size or the set itself. No memoization or overlapping subproblems.
What's the most common mistake?+
Not reading the modification rule precisely. Candidates assume it's simple (like 'double each element') when it might be 'double if even, increment if odd' or depend on position. Always write out the rule in plain English before coding.
How much time should I spend on this in the OA?+
15-20 minutes max. Parse the rule, code the transformation, use a set, return the count. If you're stuck on the wording, re-read the problem. Don't spin your wheels guessing the transformation logic.
Will they ask me to optimize space or time?+
Probably not aggressively. The hash set is O(n) space, the iteration is O(n) time. That's acceptable. Focus on correctness and clarity. If you pass, they're happy.