Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 15 of 377

Program to find minimum time required to complete tasks with k time gap between same type tasks in Python

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

Suppose we have a list of integers called tasks where each item represents a different task type, and a non-negative integer k. Each task takes one unit of time to complete and tasks must be completed in the given order, but we must have k units of time between executing two tasks of the same type. At any time, we can either execute a task or wait. We need to find the minimum time required to complete all tasks. For example, if tasks = [0, 1, 1, 2] and k = 2, the output will be 6. The first ...

Read More

Program to find array by swapping consecutive index pairs in Python

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

Given a list of numbers, we need to swap consecutive pairs at even indexes with each other, and consecutive pairs at odd indexes with each other. This creates a specific pattern where elements at positions (0, 2), (1, 3), (4, 6), (5, 7), etc. are swapped. Problem Understanding The swapping pattern works as follows ? Swap elements at indexes 0 and 2 (first even pair) Swap elements at indexes 1 and 3 (first odd pair) Swap elements at indexes 4 and 6 (second even pair) Swap elements at indexes 5 and 7 (second odd pair) Continue ...

Read More

Program to check sum of two numbers is up to k from sorted List or not in Python

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

Suppose we have a list of numbers called nums and the elements in nums are sorted in ascending order. We also have another value k, we have to check whether any two elements taken from the list add up to k or not. The numbers can also be negative or 0. We have to solve this problem in constant amount of space usage. So, if the input is like nums = [-8, -3, 2, 7, 9] k = 4, then the output will be True, because if we take 7 and -3, then the sum is 7 + (-3) ...

Read More

Program to find sum of two numbers which are less than the target in Python

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

Suppose we have a list of numbers called nums and also have a target value, we have to find the sum of the largest pair of numbers in nums whose sum is at most (target-1). So, if the input is like nums = [8, 3, 4, 9, 2] target = 8, then the output will be 7, because the sum of the largest pair of numbers less than 8 is 4 + 3 = 7. Algorithm To solve this, we will follow these steps ? Sort the list nums Initialize p1 := 0 (left pointer) ...

Read More

Program to create data structure to check pair sum is same as value in Python

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

Sometimes we need to build a data structure that efficiently checks if any two elements sum to a target value. This problem requires designing a class with two methods: add() to insert values and find() to check pair sums. Problem Statement We need to create a data structure with two operations ? add(val) − adds the value to the data structure find(val) − checks whether there are two elements whose sum equals val The key requirement is efficiency − we should be able to answer queries quickly without searching through all numbers every time. ...

Read More

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 232 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 907 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 795 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 328 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
Showing 141–150 of 3,768 articles
« Prev 1 13 14 15 16 17 377 Next »
Advertisements