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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Strings
  4. Save Humanity
  5. Discussions

Save Humanity

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 65 Discussions, By:

recency

Please Login in order to post a comment

  • bhautik4avenger4
    6 months ago+ 1 comment

    https://zeroplusfour.com/save-humanity/

    Here's how I did in all languages Java 8 , C++ , C , Python 3, Python 2.

    0|
    Permalink
  • frozendamn
    8 months ago+ 0 comments

    After a lot of cheating, it's done

    def divide_and_compare(person_substring, virus):
        str_half_len = len(virus)//2
    # compare first half
        if (person_substring[0:str_half_len] == virus[0:str_half_len]):
            # if first half matched, the culprit is in second half 
            # since we know there is a mismatch here, 
    	# there is no need to compare
            # just make a recursive call with the second halfs,
    	# but what if strings are just 1 char long? 
            if (len(virus[str_half_len:]) == 1):
                return True
            else:
                return divide_and_compare(person_substring[str_half_len:], virus[str_half_len:])
    						
        # compare second half
    elif (person_substring[str_half_len:] == virus[str_half_len:]):
            # first half did not match but second half have matched 
    	# this means culprit is in first half
            if (len(virus[0:str_half_len]) == 1):
                return True
            else:
                return divide_and_compare(person_substring[0:str_half_len], virus[0:str_half_len])
        else:
            # print('# both half did not match, so we are safe')
            return False
    				
    def virusIndices(person, virus):
        match_list = list()
        person_len = len(person)
        virus_len = len(virus)
        if(virus_len > person_len):
            print('No Match!')
            return
        loop_range = person_len - virus_len + 1
        for p_index in range(loop_range):
            person_substring = person[p_index:p_index+virus_len]
            if (person_substring == virus):
                match_list.append(p_index)
                continue
            else:
                compare_result = divide_and_compare(person_substring, virus)
                if compare_result:
                    match_list.append(p_index)    
        if len(match_list) > 0:
            print(*match_list)
        else:
            print('No Match!')
    
    0|
    Permalink
  • avaandin153
    1 year ago+ 0 comments

    yeah, Urban Ag Report is working for this moto too.

    0|
    Permalink
  • aryasimplex1811
    2 years ago+ 0 comments

    //just time limit exceeds error but code works fine

    include

    using namespace std;

    int dna(string p,string v){ int lp=p.length(); int lv=v.length(); vector result; for (int i=0; i<=lp-lv; i++){ int count=i,sum=0; for (int j=0; j

        }
        if (sum==lv-1||sum==lv)
        result.push_back(i);
    
    }
    if (result.empty()){
        cout<<"No Match!";
    }
    else{
        copy(result.begin(),result.end(),ostream_iterator<int>(cout," "));
    }
    cout<<endl;
    return 0;
    

    } int main(){ int t; cin>>t; string p[t],v[t]; for (int i=0; i>p[i]>>v[i]; }

    for (int i=0; i<t; i++){
        dna(p[i],v[i]);
    }
    

    }

    0|
    Permalink
  • emperor1
    2 years ago+ 0 comments

    So, spoiler/clues alert first. Okay? Good. This one took me a while. Javascript is sloooow at this kind of stuff. Firstly, test your strings right to left. Secondly, skip repeats. There are much more complicated approaches, but this was enough to get through.

    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy