Print Without Repeating
Reported by candidates from JP Morgan's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
JP Morgan sent you a string problem in September 2024, and the title is doing heavy lifting: Print Without Repeating. You've got maybe 48 hours and no time to pattern-match wrong. The core task is to output characters from a string but skip any that have already appeared. It's a filtering problem disguised as a print problem. The trick isn't the algorithm. It's knowing when to stop checking and move on. StealthCoder runs silent during your OA and can feed you the solution if you blank on the data structure choice.
Pattern and pitfall
This is a hash-table or set problem. You iterate once through the string, maintain a set of seen characters, and only print characters the first time you encounter them. Time complexity is linear. The pitfall candidates hit: overthinking whether you need to track indices, or trying to build a new string instead of printing as you go. Some candidates attempt sorting or frequency maps when a simple set is faster and cleaner. The pattern is straightforward once you see it, but under pressure on the OA, people second-guess themselves on edge cases like empty strings, single characters, or Unicode. StealthCoder is your safety net if the nervousness kicks in and you blank on syntax or logic flow. Code it once in practice, then trust it.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Print Without Repeating 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass JP Morgan's OA.
JP Morgan reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Print Without Repeating FAQ
Is this a string or hash-table problem?+
Both. You're iterating a string and using a set or hash-table to track what you've seen. The hash-table is the key data structure. If you approach it as just string manipulation, you'll overcompose the solution.
Do I need to preserve order?+
Yes. You print characters in the order they first appear, not sorted. A set tracks membership, but you iterate the original string to maintain sequence. That's the detail people miss.
What if the string is empty or has one character?+
Empty string outputs nothing. Single character outputs that character once. Both are trivial edge cases, but mention them in your code comments during the OA so the proctor sees you're thorough.
How hard is this problem really for JP Morgan?+
It's easy if you see the pattern. JP Morgan uses it as a baseline to verify you can code cleanly and handle a set or dictionary without overcomplication. Don't be fooled by the simplicity. Clarity and correctness matter more than a clever one-liner.
Can I solve this in one pass?+
Yes. One pass through the string, checking the set each time. If not seen, print and add to set. That's optimal. Some candidates waste time with two passes or nested loops. Don't.