Skip to content

Commit 5c17ea6

Browse files
committed
MS Strings part 4
1 parent bd3e9a3 commit 5c17ea6

7 files changed

Lines changed: 194 additions & 0 deletions

File tree

‎Third Interview/Microsoft/Strings/KthNonRepeating/.idea/description.html‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Third Interview/Microsoft/Strings/KthNonRepeating/.idea/misc.xml‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Third Interview/Microsoft/Strings/KthNonRepeating/.idea/modules.xml‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Third Interview/Microsoft/Strings/KthNonRepeating/.idea/project-template.xml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Third Interview/Microsoft/Strings/KthNonRepeating/.idea/workspace.xml‎

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
12+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.company;
2+
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
private int KthNonRepeating(String s, int k){
8+
9+
int n = s.length();
10+
int[] count = new int[n];
11+
int[] index = new int[n];
12+
13+
for(int i=0;i<n;i++){
14+
Arrays.fill(count, 0);
15+
Arrays.fill(index, n);
16+
}
17+
18+
for(int i=0;i<n;i++){
19+
char c = s.charAt(i);
20+
++count[c];
21+
if(count[c] == 1)
22+
index[c] = i;
23+
else
24+
index[c] = n;
25+
}
26+
27+
Arrays.sort(index);
28+
29+
return (index[k-1] != n)? index[k-1] : -1;
30+
}
31+
}

0 commit comments

Comments
 (0)