Skip to content

Commit 9813e27

Browse files
Merge pull request #9 from theforestvn88/august
2053
2 parents 7dd6bce + 192cdd2 commit 9813e27

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# @param {String[]} arr
2+
# @param {Integer} k
3+
# @return {String}
4+
def kth_distinct(arr, k)
5+
counter = Hash.new(0)
6+
arr.each { |x| counter[x] += 1 }
7+
# hash in ruby keep the order of the input entries
8+
counter.entries.filter { |k, v| v == 1 }[k-1]&.first || ''
9+
end

0 commit comments

Comments
 (0)