Jobra drops you into a broken repo. Find it, fix it, ship it. AI helps you debug like on the job.
Jobra drops you into a broken repo. Find it, fix it, ship it. AI helps you debug like on the job.
This is a verified interview question from Hpe. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Count Distinct Subsequences HPE - IIT Roorkee" covers key patterns like Other.
"**Mode:** On-Campus **OA Date:** 2026-11-24 ## Count Distinct Subsequences You are given a string `S` consisting of only two characters: `R` and `L`. - `R` represents a move one step to the right (+1). - `L` represents a move one step to the left (-1). You are also given three integers: `N`, `X`, and `Y`. Consider a number line containing all integers from `0` to `N` (both inclusive). You start at position `X` and need to reach position `Y`. Your task is to find the **number of distinct subsequences** of string `S` that can take you from position `X` to position `Y`. **Rules:** 1. You can choose any subsequence of the given string while maintaining the relative order of its characters. 2. Each character in the selected subsequence represents one move. 3. You must never move outside the range `[0, N]`. 4. Subsequences are considered distinct based on their resulting strings, not their indices. **Important:** If the string `S` contains multiple occurrences of the same subsequence, count it only once. For example, if `RR` can be obtained using different sets of indices, it must still be counted as only one distinct subsequence. Return the total number of distinct subsequences that take you from `X` to `Y`."
Join thousands of developers practicing for Hpe.