Skip to content

Practice Kth Distinct String in an Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2053
LeetCode Problem

Kth Distinct String in an Array

Problem Statement

A distinct string is a string that is present only once in an array. Given an array of strings arr, and an integer k, return the kth distinct string present in arr. If there are fewer than k distinct strings, return an empty string "". Note that the strings are considered in the order in which they appear in the array.

Source: Kth Distinct String in an Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
arr = ["d","b","c","b","c","a"], k = 2
Output
"a"

# Example 2

Input
arr = ["aaa","aa","a"], k = 1
Output
"aaa"

# Example 3

Input
arr = ["a","b","a"], k = 3
Output
""

Constraints

1 <= k <= arr.length <= 1000
1 <= arr[i].length <= 5
arr[i] consists of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Kth Distinct String in an Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.