Find the repeated word | Wipro previous year question paper solution

Problem of Find the repeated word | Wipro previous year question paper solution :-

‘Word Finder’ is an online game in which the player needs to enter text. The game auto detects the word occurring more than once in the player’s text .At the end of the game the repeated words are display to the player’s screen.

Write an algorithm to find the words occurring more than once in the player’s text.

input:- the input consists of a string playerText,  representing the text entered by the player.

Output:- Print space separated strings in the lexicographical sorted order representing the repeated words in the player’s text . if no word is repeated print “NA”.

Note:- A Word is an alphabetic sequence of characters with no whitespaces, and there is no punctuations in the input text.

playerText is a case sensitive (i.e cat and CAT are the different word). It consist the lower case and the upper case letter from the English alphabet.

Example of Find the repeated word | Wipro previous year question paper solution:-

input:-
cat batman latt matter batman mouse mouse latt latt

Output:-
batman latt mouse

Explanation:- The word “batman ” is repeated two times , the word “latt” is repeated three times and the word “mouse” is repeated two times in the text . So the repeated words are [batman, latt, mouse].

Code:-
```# takign input of the sentence
mystring=input()

# spliting the sentence into words
words=mystring.split()
dic={}

# counting the frequency of the words
for i in words:
if i not in dic:
dic[i]=0
dic[i]+=1

# if the frequency of the words is more than one then
# print it
for i in dic:
if dic[i]>1:
print(i,end=" ")
```

Output:-
`batman latt mouse`

Recommended Post: