Question bank › Two Pointers
Dsa Two Pointers Warm-up

Cargo Balancer

A shipping container is filled with cargo crates labeled 'L' for Light and 'H' for Heavy. To balance the ship, all 'L' crates must be moved to the front (left) and all 'H' crates to the back (right). Given a string representing the current arrangement, rearrange the crates using an in-place pointer logic. Input Format: A single string of 'L' and 'H' characters. Output Format: The rearranged string with all 'L' characters before all 'H' characters. Example: Input: HLHL Output: LLHH

Key concepts

two_pointerssorting

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.