FastPrepPair Left and Right Shoes by Size

Pair Left and Right Shoes by Size

Motive logoMotive● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

A shoe rack contains left shoes and right shoes in various integer sizes. Given the sizes of every left shoe and every right shoe, return whether every shoe can be paired with exactly one opposite-side shoe of the same size.

Function

canPairShoes(leftSizes: int[], rightSizes: int[]) → boolean

Examples

Example 1

leftSizes = [7,8,7]rightSizes = [7,7,8]return = true

Every left shoe has one right shoe of the same size.

Example 2

leftSizes = [6,6]rightSizes = [6,7]return = false

One left size-6 shoe and the right size-7 shoe remain unmatched.

Constraints

  • 0 <= leftSizes.length, rightSizes.length <= 100000.
  • 1 <= size <= 1000000000.

More Motive problems

See Motive hiring insights
public boolean canPairShoes(int[] leftSizes, int[] rightSizes) {
    // Return whether all shoes can be paired by size.
}
leftSizes[7,8,7]
rightSizes[7,7,8]
expectedtrue
Checking account…