Question

I uploaded this question twice already and no one had the expertise to answer the question correctly. Please assign an Analysis of Algorithms Expert. You're allowed to use any language (state it) providing the solution pass all test cases (they are anonymous).

Unique Codewords HackerRank Alice has devised a clever way to secretly embed a message within a sequence of strings that she

I #1/bin/python$ 3 import os 4 import sys 5 7 8 ▼if · -name------main-- nkinput().split) n int (nk[0]) k int (nk[1]) for n_

Comments
    Answer #1

    1 #!/bin/Python3 3 import os 4 import sys nk-input().split() n-int(nk[]) k-int(nk[1]) codewords [] #taking input no.of words

    #!/bin/python3

    import os
    import sys

    if __name__=='__main__':
       nk=input().split() #taking input no.of words n and k , separated by space (as string)
      
       n=int(nk[0]) #taking n
      
       k=int(nk[1]) #taking k
      
       codewords=[] #list to store the words
       words=[]
       a=[]
       for n_itr in range(n): #iterating n times to take n words
           codeword=input() #taking word
           codewords.append(codeword) #storing into a list
           words.append(codeword) #storing words in words list
      
       l=0 #starting index
       decoded_words=[] #list to store the decoded words
       for i in range(k,n,k): #iterates through list based on interval (ex:-0,2 2,4 4,6...) based on k
           a=a+words[l:i] #storing words in list a in intervals
           a.sort() #sorting list
           code_word=codewords[i-1] #code word=word at k position
           for j in a: #iterating through every word
               if j not in decoded_words and (a.count(j)==1) and (code_word<j): #if word in list is unique and not repeated(count shows the no.of occurences)
                   code_word=j
                   break #if code_word found break
           decoded_words.append(code_word) #adding the words into a list
           l=i #changing initial index to slice the list
       print("\nOutput:")
       for i in decoded_words:
           print(i) #printing the words
                  

    Output:
    jack@jack-TravelMate-P243-M: python3 code.py 7 2 ijk abc Lmn xyz ijk abc aac Output: i.jk xyz Lmn iackaiack-TravelMate-P243-M

    Try This!

    Add a comment
    Know the answer?
    Add Answer to:
    I uploaded this question twice already and no one had the expertise to answer the question correc...
    Your Answer:

    Post as a guest

    Your Name:

    What's your source?

    Earn Coins

    Coins can be redeemed for fabulous gifts.

    Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
    Similar Homework Help Questions
    ADVERTISEMENT
    Free Homework Help App
    Download From Google Play
    Scan Your Homework
    to Get Instant Free Answers
    Need Online Homework Help?
    Ask a Question
    Get Answers For Free
    Most questions answered within 3 hours.
    ADVERTISEMENT
    ADVERTISEMENT