Classic algorithms · 22 / 22 Exercise Easy

Are they permutations of each other?

Objective

Two lists are a permutation of each other if they have exactly the same elements, repeated the same number of times, even in a different order. It is checked by counting, without sorting.

Instructions

  • Read two lines, each one with values separated by spaces (they may be numbers or words).
  • Count with a dictionary how many times each value appears in each line.
  • If the two dictionaries are equal, show Yes; otherwise, No.
Input
1 2 3 2
2 3 1 2
Output
Yes

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise