Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to check typed string is for writing target string in stuck keyboard keys or not in Python

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

Sometimes keyboard keys get stuck and produce repeated characters when typing. This program checks if a typed string could have been intended to write a target string, accounting for stuck keys that repeat characters. For example, if we want to type "apple" but the 'p' and 'e' keys are stuck, we might end up typing "appppleee". This program verifies if such typing errors are possible. Problem Statement Given two strings s (typed string) and t (target string), determine if s could be the result of typing t with some stuck keyboard keys. Example If s ...

Read More

Program to check whether list is alternating increase and decrease or not in Python

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

Suppose we have a list of numbers called nums. We have to check whether the list alternates starting from strictly increasing then strictly decreasing and then strictly increasing and so on. If the list is only strictly increasing, it will also be considered valid. So, if the input is like nums = [2, 4, 8, 7, 5, 1, 5, 7, 2, 1], then the output will be True, because [2,4,8] are increasing, then [7,5,1] is decreasing, then again [5,7] is increasing and [2,1] is decreasing. Algorithm To solve this, we will follow these steps ? If nums[1]

Read More

Program to find squared elements list in sorted order in Python

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

When we have a sorted array with negative and positive numbers, squaring them can disrupt the order. We need to find squared elements and return them in sorted order efficiently. So, if the input is like nums = [-8, -3, 0, 5, 6], then the output will be [0, 9, 25, 36, 64] Algorithm To solve this efficiently in O(n) time, we use a two-pointer approach ? Initialize left pointer at start (0) and right pointer at end (n-1) Create result array and fill from the end (largest squared values first) Compare absolute values at ...

Read More

Program to sort numbers based on 1 count in their binary representation in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 5K+ Views

Sorting numbers based on the count of 1s in their binary representation is a common programming problem. When two numbers have the same count of 1s, we sort them by their actual values in ascending order. So, if the input is like nums = [4, 1, 12, 7, 6], then the output will be [1, 4, 6, 12, 7], because − Binary form of 4 is 100 (one 1) Binary form of 1 is 1 (one 1) Binary form of 6 is 110 (two 1s) Binary form of 12 is 1100 (two 1s) Binary form of 7 ...

Read More

Program to find smallest pair sum where distance is not consecutive in Python

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

When working with arrays, we sometimes need to find pairs of elements that satisfy specific distance constraints. In this problem, we want to find the smallest sum of two elements where their indices are not consecutive (distance greater than 1). Problem Understanding Given a list of numbers, we need to find any pair of indices (i, j) where i < j and j - i > 1, then return the smallest possible sum. This means we cannot select adjacent elements. For example, with nums = [3, 4, 2, 2, 4], we can select values 3 and 2 ...

Read More

Program to form smallest number where no two adjacent digits are same in Python

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

Suppose we have a string s with four possible characters "1", "2", "3" and "?". We can place any one of "1", "2" and "3" in the place of "?". We have to find the smallest possible number that we can make such that no two adjacent digits are same. So, if the input is like s = "2??3?", then the output will be 21231. Algorithm To solve this, we will follow these steps − Convert the string to a list for easy modification Handle the special ...

Read More

Program to find length of shortest sublist with maximum frequent element with same frequency in Python

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

Suppose we have a list of numbers called nums. If the frequency of a most frequent number in nums is k, we have to find the length of the shortest sublist such that the frequency of its most frequent item is also k. So, if the input is like nums = [10, 20, 30, 40, 30, 10], then the output will be 3, because here the most frequent numbers are 10 and 30, where k = 2. If we select the sublist [30, 40, 30], this is the shortest sublist where 30 appears with its maximum frequency of 2. ...

Read More

Program to check right rotation forms increasing or decreasing array with first n natural numbers or not in Python

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

Suppose we have a list of numbers called nums, where n elements are present. We have to check whether we can make a list with first n natural numbers either in increasing or decreasing fashion, like [1, 2, ..., n] or [n, n - 1, ..., 1] by shifting nums to the right any number of times or not. So, if the input is like nums = [5, 6, 1, 2, 3, 4], then the output will be True, because we can shift them four times to make the array [1, 2, 3, 4, 5, 6]. Algorithm ...

Read More

Program to define set data structure without using library set class in Python

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

A set is a collection of unique elements. We can implement a custom set data structure without using Python's built-in set class by creating a class with basic set operations. Set Operations to Implement Our custom set class will support the following methods ? Constructor to create a new set instance add(val) to insert an integer into the set exists(val) to check if a value exists in the set remove(val) to remove a value from the set Implementation Approach We'll use a dictionary where each key represents a value and maps to a ...

Read More

Program to check whether all can get a seat or not in Python

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

Suppose we have a number n, there are n number of people searching for a seat, we also have a list of bits where 1 represents an already occupied seat and 0 represents empty seat. No two people can sit next to each other, so we have to check whether all n people can find a seat or not. So, if the input is like n = 2 seats = [1, 0, 0, 0, 1, 0, 0], then the output will be True, because they can seat at index 2 and 6. Approach To solve this, we ...

Read More
Showing 2941–2950 of 61,297 articles
« Prev 1 293 294 295 296 297 6130 Next »
Advertisements