TuSimple

Online Assessment
Online Assessment//Count the Number of Good Subsequences
Q2
Medium50 Marks

Count the Number of Good Subsequences

Hash TableMathStringCombinatorics
Set 1 • 90 min
Problem Statement

In TuSimple's technical coding assessment, candidates are evaluated on clean algorithmic problem-solving for "Count the Number of Good Subsequences".

Given standard input parameters adhering to Hash Table principles, design an optimal algorithm that satisfies all constraints and handles boundary test scenarios efficiently.

Ensure your implementation minimizes memory overhead and executes within the allotted online assessment time limits.

Candidate Instructions
  • ▸Identify the core invariant related to Hash Table.
  • ▸Verify edge cases including empty inputs and extreme bounds.
  • ▸Optimize time complexity before submitting.
Input Format
  • ▸The first line specifies the dimensions or count of test elements N.
  • ▸The subsequent line(s) contain the input array, string, or graph representation.
Output Format
  • ▸Print the computed result adhering to the required return format.
Constraints
  • 1 <= N <= 10^5
  • -10^9 <= element[i] <= 10^9
  • Time Limit: 2.0 seconds
  • Memory Limit: 256 MB
Edge Cases
  • ▸Empty or single-element input
  • ▸Input containing maximum or minimum boundary values
  • ▸Uniform elements or all-negative test cases
Sample Test Cases
Example 1
Input
nums = [1, 2, 3, 4, 5], k = 3
Output
3
Explanation

Applying the optimal Hash Table approach yields the expected solution 3.

Complexity
TimeO(N)
SpaceO(N)
Expected Approach

Leverage Hash Table combined with Math, String, Combinatorics, Counting to process the input in optimal O(N) time complexity.