[GE][First Method]Find smallest permutation of given number
Smallest number by rearranging digits of a given number Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Examples: Input: n = 846903 Output: 304689 Input: n = 55010 Output: 10055 Steps to find the smallest number. Count the frequency of each digit in the number. Place the smallest digit (except 0) at the left most of required number. and decrement the frequency of that digit by 1. Place all remaining digits in ascending order from left to right. This solution is based on counting sort . // C++ program for finding smallest number // from digits of given number #include<iostream> using namespace std; // function to find the smallest number int smallest( int num) { // initialize frequency of each digit to Zero int freq[10] = {0}; // count frequency of e...
https://www.geeksforgeeks.org/zigzag-or-diagonal-traversal-of-matrix/
ReplyDelete