You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Chacha Chaudhary has asked Sheena to find out the Nth occurence of any Word in the Paragraph. Sheena finds it a tedious task to find Nth occurence so she wants you to write a small java program which can solve her problem and she will give you a gift for helping her. Let us write a code.
3
+
4
+
Input Format
5
+
6
+
First line reads the paragraph contents
7
+
8
+
Second line reads the word to be found and N separated by Space
9
+
10
+
Constraints
11
+
12
+
N>0
13
+
14
+
Output Format
15
+
16
+
Prints the starting index of the Nth occurence of the word in the paragraph
17
+
18
+
Prints Not Present if not occuring even a single time and prints the last occurence if occuring less than N times.
19
+
20
+
Sample Input 0
21
+
22
+
Aana bought banana.
23
+
ana 1
24
+
Sample Output 0
25
+
26
+
1
27
+
Sample Input 1
28
+
29
+
Aana bought banana
30
+
baa 3
31
+
Sample Output 1
32
+
33
+
Not Present
34
+
Sample Input 2
35
+
36
+
Aana bought banana.
37
+
ba 3
38
+
Sample Output 2
39
+
40
+
12
41
+
Explanation 2
42
+
43
+
ba is occuring only 1 time i.e. at index 12. 3rd occurence is not available so output is 12 which is the last occurence.
44
+
*/
45
+
46
+
47
+
importjava.io.*;
48
+
importjava.util.*;
49
+
50
+
publicclassSolution {
51
+
52
+
publicstaticvoidmain(String[] args) {
53
+
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
0 commit comments