Skip to content

Commit fe169cf

Browse files
authored
Create Kth Distinct String in an Array.java
1 parent b622577 commit fe169cf

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import java.util.Map.Entry;
2+
3+
class Solution {
4+
public String kthDistinct(String[] arr, int k) {
5+
return Arrays.stream(arr).collect(
6+
Collectors.groupingBy(Function.identity(), LinkedHashMap::new, Collectors.counting()))
7+
.entrySet().stream().filter(entry -> entry.getValue().equals(1L)).map(Entry::getKey)
8+
.skip(k - 1)
9+
.findFirst().orElse("");
10+
}
11+
}

0 commit comments

Comments
 (0)