Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a function to count unique characters in a string.

Hard

Problem Statement

Write a function to count unique characters in a string.

Sample Input

A hardcoded string, e.g., "programming".

Sample Output

Number of unique characters: 8

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
fun countUniqueCharacters(input: String): Int { return input.toSet().size } fun main() { val input = "programming" println("Number of unique characters: ${countUniqueCharacters(input)}") }
Log in or sign up to run or submit your code.Log inSign up
Input
A hardcoded string, e.g., "programming".
Expected Output
Number of unique characters: 8