Company: Harness__

Difficulty: medium

Problem Statement

Problem Description Picture an endless row of lockers, numbered from left to right starting at 1. Some of these lockers currently hold a key, with at most one key per locker. You want to rearrange the keys so that they end up filling a single unbroken run of lockers, with no gaps between them. In one move you may take any one key and place it into an empty locker. Given an array balls listing the locker numbers that currently hold a key, determine the smallest number of moves needed to gather all the keys into consecutive lockers. Examples Example 1 Input: balls = [6, 4, 1, 7, 10] Output: 2

More Harness__ OA questionsInterview experiences