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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Strings
  4. Save Humanity
  5. Discussions

Save Humanity

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 68 Discussions, By:

recency

Please Login in order to post a comment

  • yashparihar729
    1 month ago+ 0 comments

    Here is my solution in java, javascript, python, C, C++, Csharp HackerRank Save Humanity Problem Solution

    0|
    Permalink
  • mineman1012221
    2 months ago+ 0 comments

    Here is the solution of Save Humanity Click Here

    -1|
    Permalink
  • eiduladh_a_wish1
    3 months ago+ 1 comment

    Strictly speaking, a dental clinic is a facility where dentists and dental staff provide care. But you'll often hear the term used to mean a place where dental services are available at a lower cost than at a private practice. Dental clinics also frequently serve an educational purpose.

    0|
    Permalink
  • bhautik4avenger4
    11 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
    1 year ago+ 1 comment

    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
Load more conversations

Need Help?


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