Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 48 of 377

Program to find smallest string with a given numeric value in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 556 Views

Given two values n and k, we need to find the lexicographically smallest string whose length is n and numeric value equals k. The numeric value of a lowercase character is its position in the alphabet (starting from 1), so 'a' = 1, 'b' = 2, and so on. The numeric value of a string is the sum of its characters' numeric values. For example, if n = 4 and k = 16, the output will be "aaam" because the numeric value is 1+1+1+13 = 16, and this is the smallest string with length 4 and value 16. ...

Read More

Program to find minimum operations to reduce X to zero in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 426 Views

We have an array called nums and a value x. In one operation, we can delete either the leftmost or rightmost element from the array and subtract its value from x. We need to find the minimum number of operations to reduce x to exactly 0. The key insight is to use prefix and suffix sums. We can precompute all possible left prefix sums, then iterate through right suffix sums to find the optimal combination. Algorithm Steps The approach involves these steps − Create a map of left prefix sums with their indices For each ...

Read More

Program to count minimum deletions needed to make character frequencies unique in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 342 Views

Given a string s, we need to make it "good" by ensuring no two different characters have the same frequency. A good string has unique frequencies for each character. We must find the minimum number of character deletions required. For example, if s = "ssstttuu", we have 3 's', 3 't', and 2 'u' characters. Since both 's' and 't' have frequency 3, we need to delete characters to make frequencies unique. Approach The strategy is to count character frequencies, sort them, and reduce duplicate frequencies by deleting characters − Count ...

Read More

Program to count sorted vowel strings in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 774 Views

Suppose we have a number n, we have to find the number of strings of size n that consist only of vowels (a, e, i, o, u) and they are lexicographically sorted. We can say that a string s is lexicographically sorted when for all valid index i, s[i] is the same as or comes before s[i+1] in the alphabet. So, if the input is like n = 2, then the output will be 15 because there are many strings like ["aa", "ae", "ai", "ao", "au", "ee", "ei", "eo", "eu", "ii", "io", "iu", "oo", "ou", "uu"]. Understanding the ...

Read More

Program to count substrings that differ by one character in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 308 Views

Suppose we have two strings s and t, we have to find the number of ways we can select a nonempty substring of s and replace one single character by another different character such that the resulting substring is one of the substring of t. We have to find the number of substrings that satisfy the condition above. So, if the input is like s = "sts" t = "tsts", then the output will be 6 because the following are the pairs of substrings from s and t that differ by 1 character − ...

Read More

Program to find path with minimum effort in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 495 Views

Finding the path with minimum effort involves navigating through a 2D matrix where we need to minimize the maximum absolute difference between consecutive cells. This problem is solved efficiently using Dijkstra's algorithm with a priority queue. Problem Understanding Given a 2D matrix heights of size m × n, we start at position (0, 0) and want to reach (m-1, n-1). We can move in four directions: up, down, left, or right. The effort of a path is defined as the maximum absolute difference between consecutive cells along that path. For example, with the matrix: 234 ...

Read More

Program to find best team with no conflicts in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 582 Views

Suppose we have two lists called scores and ages, where scores[i] and ages[i] represent the score and age of the ith player in a basketball game. We want to select the team with the highest overall score, where the team score is the total sum of scores of all selected players. However, we must avoid conflicts − a conflict exists if a younger player has a strictly higher score than an older player. So, if the input is like scores = [5, 7, 9, 14, 19], ages = [5, 6, 7, 8, 9], then the output will be 54 ...

Read More

Program to find lexicographically smallest string after applying operations in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 345 Views

Suppose we have a string s with only numeric digits and also have two values a and b. We can apply any one of the following two operations any number of times and in any order on s ? Add 'a' to all odd positioned items of s (0-indexed). If digit is 9, then by adding something with it will be cycled back to 0. Rotate 's' to the right by b positions. We have to find the lexicographically smallest string we can get by applying the above operations any number of times on s. ...

Read More

Program to find number of sets of k-non-overlapping line segments in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 393 Views

Suppose we have n points on a line, where the ith point (from 0 to n-1) is at position x = i, we have to find the number of ways we can draw exactly k different non-overlapping line segments such that each segment covers two or more points. The endpoints of each line segment must have integral coordinates. The k line segments do not have to cover all given n points, and they can share endpoints. If the answer is too large, then return result mod 10^9+7. So, if the input is like n = 4, k = 2, ...

Read More

Program to find maximal network rank in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 499 Views

The maximal network rank problem asks us to find the maximum combined connectivity between any two cities in a road network. The network rank of two cities is the total number of roads directly connected to either city, counting shared roads only once. Given a network where roads[i] = [u, v] represents a bidirectional road between cities u and v, we need to find the pair of cities with the highest combined connectivity. Understanding the Problem For any two cities, their network rank equals: Number of roads connected to city 1 Plus number of roads connected ...

Read More
Showing 471–480 of 3,768 articles
« Prev 1 46 47 48 49 50 377 Next »
Advertisements