The document outlines ten algorithmic problems with specific constraints and requirements. Each problem involves operations on strings, arrays, or data structures, and emphasizes efficiency with time complexity constraints ranging from O(N) to O(N log N). Examples are provided for clarity, including tasks like lexicographically smallest subsequence removal, dynamic seating arrangements, string compression, and more.
The document outlines ten algorithmic problems with specific constraints and requirements. Each problem involves operations on strings, arrays, or data structures, and emphasizes efficiency with time complexity constraints ranging from O(N) to O(N log N). Examples are provided for clarity, including tasks like lexicographically smallest subsequence removal, dynamic seating arrangements, string compression, and more.
Lexicographically Smallest Subsequence Removal with Constraints
You are given a string S of length N consisting of lowercase English letters. You must remove exactly K characters from S such that the resulting string is lexicographically smallest. You cannot change the order of the remaining characters. Return the final string after removal. If multiple answers exist, return the first lexicographically smallest one. Constraints: o 1 ≤ N ≤ 10⁵ o 0≤K≤N o S consists of lowercase English letters only. o The algorithm should run in O(N) time complexity. Example: o Input: "abcde", K = 2 o Output: "abc" 2. Dynamic Arrangement of Seating in a Circular Table In a circular restaurant, N guests arrive in sequential order and must be seated following these rules: o Each guest i prefers to sit Pi places away from the previous guest (clockwise). o If a seat is occupied, the guest moves to the next available one. o The arrangement starts at seat 1 and continues clockwise. Given N and an array P of size N, return the final seating arrangement. If a guest cannot be seated, return "Seating Not Possible". Constraints: o 2 ≤ N ≤ 10⁵ o 1 ≤ Pi ≤ N o Each guest arrives sequentially. o The algorithm should run in O(N log N). Example: o Input: N = 4, P = [1, 2, 2, 1] o Output: [1, 3, 2, 4] 3. Advanced String Compression Mechanism You are given a string S consisting of lowercase letters. Perform string compression using the following rules: o Consecutive occurrences of a character should be replaced by the character followed by its count. o If a compressed character's count is 1, it should not be included. o If the compressed string is longer than the original string, return the original string. Constraints: o 1 ≤ |S| ≤ 10⁵ o S consists of lowercase letters only. Example: o Input: "aaabbcddd" o Output: "a3b2cd3" o Input: "abc" o Output: "abc" 4. Optimized Delivery Scheduling for Autonomous Drones A delivery service has N delivery locations and K autonomous drones. Each drone can carry exactly W kg, and each location has a package weight requirement P[i]. You must find the minimum number of drone trips required to deliver all packages optimally. Constraints: o 1 ≤ N, K ≤ 10⁵ o 1 ≤ W ≤ 10⁴ o 1 ≤ P[i] ≤ W o Packages cannot be split across drones. o The algorithm should run in O(N log N). 5. Recursive Path Formation in a Grid with Dynamic Barriers Given an M × N grid, a robot starts from (0,0) and must reach (M-1, N-1). Some cells contain barriers (X), which the robot cannot pass. The robot can only move right or down. Return the number of unique paths from the start to the destination. Constraints: o 1 ≤ M, N ≤ 1000 o The grid contains 0 (open path) and X (barrier). o The solution must use dynamic programming with O(MN) complexity. 6. Maximum Sum Subarray with No Adjacent Elements Given an array A of size N, find the maximum sum possible by selecting non- adjacent elements. You cannot pick two consecutive elements. Constraints: o 1 ≤ N ≤ 10⁶ o -10⁴ ≤ A[i] ≤ 10⁴ o The solution must run in O(N) using dynamic programming. 7. Bitwise XOR Manipulation of Large Datasets Given an array of N integers, perform the following operation exactly K times: o Pick any two numbers A[i] and A[j] (where i ≠ j), and replace both with A[i] XOR A[j]. o Return the maximum possible sum of the array after K operations. Constraints: o 1 ≤ N ≤ 10⁵ o 1 ≤ K ≤ 10⁴ o 1 ≤ A[i] ≤ 10⁶ o Solution must run in O(N log N). 8. Efficient Detection of Anagrams in a Text Stream Given a string S of length N and a pattern P of length M, find all starting indices where an anagram of P exists in S. The result must be returned in an array. Constraints: o 1 ≤ N, M ≤ 10⁵ o S and P consist of lowercase English letters. o Solution should use Sliding Window and run in O(N). 9. Simulating a Double-Ended Priority Queue with Fast Insertions Implement a data structure that supports the following operations: o insert(x): Inserts x into the structure. o deleteMax(): Removes and returns the maximum element. o deleteMin(): Removes and returns the minimum element. o getMax(): Returns the maximum without deletion. o getMin(): Returns the minimum without deletion. Constraints: o 1 ≤ Q ≤ 10⁵ (Number of operations) o 1 ≤ x ≤ 10⁶ o Solution must use balanced trees or heaps with O(log Q) complexity. 10.Customizable Sorting Algorithm for Large Numerical Inputs Given a list of N numbers, sort them based on the following: If the number is even, it should be sorted in ascending order. If the number is odd, it should be sorted in descending order. Maintain the relative order of odd and even numbers separately. Constraints: 1 ≤ N ≤ 10⁶ 1 ≤ A[i] ≤ 10⁶ Solution must run in O(N log N).