Menu
Coddy logo textTech

Swaps to Minimum

Lesson 13 of 15 in Coddy's Recursion Challenges - Master The Recursive Thinking course.

challenge icon

Challenge

Hard

Write a function named minFind that gets an integer num and an integer k and returns the smallest number that can be generated after at most k swaps.

Examples,

  • minFind(3421, 1)  ->  1423 (1 - 3)
  • minFind(3421, 2)  ->  1243 (1 - 3, 2 - 4)
  • minFind(4231, 2)  ->  1234 (Minimum number after 1 swap)

Try it yourself

#include <stdio.h>
#include <stdlib.h>

int minFind(int num, int k) {
    // Write code here
    return num;
}

All lessons in Recursion Challenges - Master The Recursive Thinking