For all HackerRank Daily Challenge problems, solved in Python. Each directory contains the problem text, my solution, and tests from HackerRank python challenge algorithms python3 hackerrank dailyprogrammer big-o dynamic-programming substring hackerrank-solutions python-algorithms daily-coding-problem Update...
HackerRank - Substring Diff Really interesting problem. Naive solution would be O(n^3). But please note the pattern here: (i, j, k) -> (i + 1, j + 1, k) -> (i + 2, j + 2, k)... this sequence shares the same pattern, so now the problem can be deducted to "what is...
My solution for hackerrank puzzles. Contribute to santik/hackerrank development by creating an account on GitHub.
classSolution {public:intlengthOfLongestSubstringKDistinct(strings,intk) { unordered_map<char, unsigned>hm;intret =0, start =0;for(inti =0; i < s.length(); i++) { hm[s[i]]++;if(hm.size() <=k) { ret= std::max(ret, i - start +1); }else{while(start < i && hm.size(...
algorithms binary-search primality-testing longest-palindromic-substring Updated Sep 19, 2020 Python pptacher / hackerrank Sponsor Star 0 Code Issues Pull requests regular-expression suffixarray longest-common-prefix dc3 deterministic-finite-automaton longest-palindromic-substring Updated May 31, 2020...
classSolution {public://Idea is like Mono-QueueintlengthOfLongestSubstring(strings) {intlen =s.length();if(len <1)returnlen;intmaxLen =1; unordered_map<char,int>rec;intstart =0;inti;for(i =0; i < len; i++) {charc =s[i];if(rec.find(c) ==rec.end()) ...
classSolution {public:stringlongestPalindrome(strings) { size_t slen=s.length();if(slen <2)returns;//inserting tokens to original stringstringns ="#";for(auto c : s) { ns+=c; ns+="#"; }//size_t len =ns.length(); vector<size_t> rec(len,0);intmaxi =1, maxr =0;intci =...
2345678 Brutal force works - and a smarter way is to utilize KMP. The most popular two solutions are essentially the same - one is obvious KMP, and another one is https://discuss.leetcode.com/topic/68206/easy-python-solution-with-explaination , which simplifies the code a lot - bravo!
2D DP is an intuitive solution of course, but I got an MLE error, so I simplified it into a 1D DP: classSolution {public:voidgoDp(vector<int> &dp,int&maxLen,int&is,int&ie,intstartLen,intlen,string&s) {for(intilen = startLen; ilen < len; ilen +=2)for(inti =0; i < len ...
Algorithms, Distributed System, Machine Learning <2025年1月> 日一二三四五六 2930311234 567891011 12131415161718 19202122232425 2627282930311 2345678 公告 昵称:Tonix 园龄:14年8个月 粉丝:2 关注:2 +加关注 A typical sliding window solution. View Code ...