We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below:
my solutions
pubfnseparate_numbers(s:&str){//Time complexity: O(n^2)//Space complexity (ignoring input): O(n)//Python solution is way cleaner, made this one first and got lazy to rewriteletlen_s=s.len();iflen_s==1{println!("NO");return;}letvec_chars=s.chars().collect::<Vec<char>>();letmutstart_number_size=1;letmutnumber_size=start_number_size;letmutindex:usize=start_number_size;letmutlast_number=vec_chars[0].to_string().parse::<i64>().expect("To have a number");letmutfirst_number=last_number;loop{if(last_number+1)==(10u64.pow(number_sizeasu32)asi64){number_size+=1;}letnumber=ifnumber_size+index>len_s{last_number+2}else{vec_chars[index..(number_size+index)].iter().collect::<String>().parse::<i64>().expect("To have a number")};if((number-last_number)!=1)||(index+number_size>len_s){start_number_size+=1;ifstart_number_size>(len_s+1)/2{println!("NO");return;};number_size=start_number_size;index=0;ifvec_chars[0]=='0'{println!("NO");return;}last_number=vec_chars[0..start_number_size].iter().collect::<String>().parse::<i64>().expect("To have a number");first_number=last_number;}else{last_number=number;}index+=number_size;ifindex==len_s{println!("YES {first_number}");return;}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Separate the Numbers
You are viewing a single comment's thread. Return to all comments →
Rust best solution
If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions