Unique subsequences
Practice
3.2 (40 votes)
Algorithms
Arrays
String manipulation
String manipulation
Problem
58% Success 8880 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a string \(S\) that contains \(N\) characters. Your task is to determine the maximum possible size of the subsequence \(T\) of \(S\) such that no two adjacent characters in \(T\) are the same.

Note: The string contains only lowercase English alphabets.

Input format

  • First line: A single integer \(T\) denoting the number of test cases
  • For each test case:
    • First line: Single integer \(N\) denoting the size of the string
    • Second line: \(S\) denoting the string

Output format

For each test case, print a single line containing one integer that represents the maximum size of the subsequence that satisfies the provided condition.

Constraints

\(1 \le T \le 10^3\\ 1 \le N \le 10^5\)

Note: The sum of \(N\) overall test cases do not exceed \(10^6\).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
17 votes
Tags:
AlgorithmsBasic ProgrammingEasyString Manipulation
Points:20
12 votes
Tags:
Ad-HocEasyString Manipulationapproved
Points:30
29 votes
Tags:
AlgorithmsApprovedImplementationMediumOpenTrees