11 N Digit numbers with digits in increasing order
Vložit
- čas přidán 7. 09. 2024
- Given an integer N, print all the N digit numbers in increasing order, such that their digits are in strictly increasing order(from left to right).
Example 1:
Input:
N = 1
Output:
0 1 2 3 4 5 6 7 8 9
Explanation:
Single digit numbers are considered to be
strictly increasing order.
------------------------------------------------------------------------------------------
Here are some of the gears that I use almost everyday:
🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
👨🏻💻 : My Apple Macbook pro: amzn.to/3w8iZh6
💻 : My gaming laptop: amzn.to/3yjcn23
📱 : My Ipad: amzn.to/39yEMGS
✏️ : My Apple Pencil: amzn.to/3kMnKYf
🎧 : My Headphones: amzn.to/3kMOzM7
💺 : My Chair: amzn.to/385weqR
🛋 : My Table: amzn.to/3TyU2IU
⏰ : My Clock: amzn.to/3slFUV3
🙋🏻♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.
Bhaiya please complete the DP playlist 🙏
I was watching the playlist and was just worried that why 1 video is hidden but as i reached upto this video it was available thanks. waiting for more.
Why back tracking needed here!! Clean and simple.
void Digits(String s, integer start, integer n, Array List list)
{
if (n== 0)
list add your s (after parsing them into an integer object directly.)
return;
}
for loop X from 1 to 9
Digits (s + X, X+1, n - 1 , list)
}
we could have taken a string instead of a vector so that we change and remove the characters at ease , below is my approach
void solve(int idx,string &str,int k,vector &res){
//base case
if(str.size()==k){
res.push_back(stoi(str));
return ;
}
for(int j=idx+1;j
i did the same just pehla n=1 mei 0 nahi aaraha tha wahi bas yeh bhi ez hai
You are the best Instructor of DSA on CZcams. I have watched all your playlists. Please make Trees playlist. PLEASEEEEEE.
I am very grateful to you for your videos. But the solution in this video is a bit unoptimized. We dont need a vector to store digits of the number. here is a solution
void solve(int &num, int remainingDigits, vector &ans){
if(remainingDigits == 0){
ans.push_back(num);
return;
}
int largestDigit = num%10;
//largest digit is the last digit
num *= 10;
for(int i=largestDigit+1; i
You are right!!
What's need of n=n/10. It is working fine without it also.
@@kanganabhargava1273 I am assuming you meant the code is running without num = num/10. If you look closely, in the solve function, I am passing num as pass by reference (for space optimization). It will work without num=num/10 if you use int num as pass-by-value in the solve method.
Hope this helps !
python code:
# Time Complexity: 9^n
def increasingNumber(n):
res = []
# handle n = 1 case explicitely
if n == 1:
res = [i for i in range(10)]
return res
vec = []
def solve(vec, res, n):
# base condition
if n == 0:
# combine vec and append to res
ans = 0
for i in range(len(vec)):
ans = (ans * 10) + vec[i]
res.append(ans)
return
# iterate over choices
for i in range(1, 10):
# controlled recursion
if len(vec) == 0 or i > vec[-1]:
vec.append(i)
# recursion call
solve(vec, res, n-1)
# backtrack
vec.pop()
solve(vec, res, n)
return res
Thanks for the explanation Aditya!
bro even if the video is long it works, or break it in 2 parts as you have been doing before, I would request you to keep teaching time complexity for few more videos and then after some of the questions you can leave it on us
Same here i just opened to complete the heap series and saw new video uploaded , happy to see you back bhaiya , keep up the good work. love you bhai dheeer sara
Java Solution :
Using String hence backtrack wouldn't matter:
public static void main(String[] args) {
int N = 5;
String op = "";
digits(N, op);
}
private static void digits(int n, String op) {
if (op.length() == n) {
System.out.println(op);
return;
}
if (op.isEmpty()) {
for (int i = 0; i
did this question by myself without seeing the vid
hey i have a request. in dp playlist you never made any video on longest increasing subsequence type problems. please make some videos on this pattern and how to approach this pattern please. humble request... :)
a solution using a different approach (strings instead of vector)
class Solution {
public:
void solve(int curr, int n, string &str, vector &res){
if(str.size() == n){
res.push_back(str);
return;
}
for(char c='1'; c str[curr-1]){
str+=c;
solve(curr+1, n, str, res);
str.pop_back();
}
}
}
vector increasingNumbers(int n) {
// Write Your Code here
vector ans;
if(n==1){
for(int i=0;i
Abhi isiliye channel khola tha ki bhai ko comment karte hai ki series puri kre, aur bhai ne nyi video upload kardi😊
Can you please tell names of questions for the DP patterns you have not covered in your playlist but discussed in the first video like Fibonacci(7 questions) LIS(10 questions) Kadane's (6 questions) DP on grid(14) others(3)
Java Solution:
class Solution {
static ArrayList list;
public static ArrayList increasingNumbers(int n) {
list = new ArrayList();
ArrayList temp = new ArrayList();
if(n == 1){
for(int i=0; i
bhaiya after this start trees thank you
Bhiaya sorry par mujhe aapka channel hindi me best explanation wala laga ,aur mere may be may ke baad se company aana start ho jayengi par oncapmus ke liye mujhe arrays aur strings ki series ki requirement thi , umeed aaapse hi kar rha hu please , request hai
King is back 😎
Agaya bhai dubara ❤
Holy f mujhai laga bhai tapak gaya😢....Glad you're doing good 😊👍
baaki videos v bana do bhaiya 🥺. thank you.
Finally, bro, came back🤩❤.
Bhaiya after this playlist will you upload video on a topic tree.??
Bhai please complete dp
Bhaiya aap DP series complete karwa do please
and baki topics bhi le aao
also if possible then striver bhaiya wali sheet types patterns match kar sakte ho toh best not telling to copy but
Thank you brother
bhaiya yar thoda graph bhi padha do esake bad please and please take cses problem set graph question
Welcome Again
"9!" hoga na time complexity?
Sir pls kindly add subtitles in dp playlist sir pls sir
love u 3000 bhaiya ❤❤
Bhai poori kardo please yarr ❤❤
133 view but itne kam like ?
Bhai 🤩
the real slim shady
❤
Bro❤❤❤