Dsa
Sorting
Medium
Distinct Prime Factor Sorter
Given a list of integers, sort them based on the number of distinct prime factors each number has (descending). If two numbers have the same number of distinct prime factors, sort them based on the value of their largest prime factor (descending). If they are still tied, sort them by the original number in ascending order.
Example:
Input: '10 12 15'
- 10: factors {2, 5}. Count: 2, Max: 5.
- 12: factors {2, 3}. Count: 2, Max: 3.
- 15: factors {3, 5}. Count: 2, Max: 5.
Sorted: 10 (2,5), 15 (2,5), 12 (2,3)
Output: '10 15 12'
Key concepts
sortingnumber-theoryprime-factors
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