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
fnpicking_numbers(a:&[i32])->i32{//Time complexity: O(n)//Space complexity (ignoring input): O(n)//You don't need to check for value-1 cases, because that is already checked by the value//itself + 1letmuta_dict=std::collections::HashMap::new();for&valueina{matcha_dict.get(&value){Some(f)=>a_dict.insert(value,f+1),None=>a_dict.insert(value,1),};}letmutlongest_subsequence_len=0;letmutcurrent_subsequence_len=0;for(value,frequency)ina_dict.iter(){letplus_len=*a_dict.get(&(*value+1)).unwrap_or(&0);current_subsequence_len=frequency+plus_len;ifcurrent_subsequence_len>longest_subsequence_len{longest_subsequence_len=current_subsequence_len}}longest_subsequence_len}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Picking 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