Backtracking
97 / 170BacktrackingLesson 4 of 10About 93 min
One line, and understanding exactly why it is that line rather than a similar one.
Write both guard styles. distinct_combinations lists every distinct combination of the given size from a list that may contain repeats. distinct_arrangements lists every distinct ordering of a list that may contain repeats. Sort first in both.
Tests
print(distinct_combinations([1, 2, 2], 2))print(distinct_combinations([1, 1, 1], 2))print(distinct_arrangements([1, 1, 2]))print(distinct_arrangements([]))Output
Run tests to see output.
Read the constraints first and let them tell you what complexity is expected. Derive the approach, implement it, run the tests, and submit when it passes.
Read the constraints first and let them tell you what complexity is expected. Derive the approach, implement it, run the tests, and submit when it passes.