In this tutorial, we are going to write a program that finds the k-th boom number.
The number that contains only 2 and 3 are called boom number.
Let's see the steps to solve the above problem.
Let's see the code.
#include<bits/stdc++.h> using namespace std; void findKthBoomNumber(long long k) { queue<string> queue; queue.push(""); long long count = 0; while (count <= k) { string numberOne = queue.front(); queue.pop(); string numberTwo = numberOne; queue.push(numberOne.append("2")); count++; if (count == k) { cout << numberOne << endl; break; } queue.push(numberTwo.append("3")); count++; if (count == k) { cout << numberTwo << endl; break; } } } int main() { long long k = 45; findKthBoomNumber(k); return 0; }
If you run the above code, then you will get the following result.
23332
If you have any queries in the tutorial, mention them in the comment section.