Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 158 of 377

Remove Nth Node From End of List in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 777 Views

Removing the Nth node from the end of a linked list is a common programming problem. Given a linked list and a number n, we need to remove the node that is n positions from the end and return the modified list head. For example, if we have a list [1, 2, 3, 4, 5, 6] and n = 3, we remove the 3rd node from the end (which is 4), resulting in [1, 2, 3, 5, 6]. Algorithm Steps We use a two-pointer approach to solve this efficiently ? If there is only one ...

Read More

Letter Combinations of a Phone Number in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 3K+ Views

The Letter Combinations of a Phone Number problem involves generating all possible letter combinations that a string of digits (2-9) could represent on a phone keypad. Each digit maps to a set of letters, similar to old telephone keypads. Phone Keypad Mapping 1 2abc 3def 4ghi 5jkl 6mno 7pqrs 8tuv 9wxyz * 0 # For example, if the input is "23", the possible combinations are ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]. Algorithm Approach We'll use backtracking to solve this problem: ...

Read More

3Sum in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 6K+ Views

The 3Sum problem asks us to find all unique triplets in an array that sum to zero. Given an array of integers, we need to identify three elements a, b, c such that a + b + c = 0. For example, in array [-1, 0, 1, 2, -1, -4], the triplets [[-1, -1, 2], [-1, 0, 1]] satisfy this condition. Algorithm Approach We use the two-pointer technique with these steps ? Sort the array to enable two-pointer approach Fix one element and use two pointers for the remaining two elements Skip duplicates to ensure unique ...

Read More

Container With Most Water in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 511 Views

The Container With Most Water problem asks us to find two vertical lines that can hold the maximum amount of water. Given an array of heights, we need to find two positions that form a container with the largest area. Problem Understanding Given an array of non-negative integers where each value represents the height of a vertical line, we need to find two lines that together with the x-axis form a container that can hold the most water. The area is calculated as width × minimum_height. Container With Most Water ...

Read More

Longest Palindromic Substring in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 11K+ Views

Finding the longest palindromic substring in a string is a classic dynamic programming problem. A palindrome reads the same forwards and backwards, like "BAB" or "RACECAR". We'll use a 2D table to track which substrings are palindromes. Algorithm Overview The approach uses dynamic programming with these steps ? Create a 2D boolean matrix where dp[i][j] represents if substring from index i to j is a palindrome Initialize single characters as palindromes (diagonal elements = True) Check substrings of increasing length, starting from length 2 For each substring, check if first and last characters match and the ...

Read More

Autorun a Python script on windows startup?

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

Making a Python script run automatically when Windows starts can be useful for background tasks, monitoring applications, or system utilities. There are two main approaches: using the Startup folder or modifying the Windows Registry. Method 1: Using Windows Startup Folder The simplest approach is to place your Python script (or a shortcut to it) in the Windows Startup folder. Windows automatically runs all programs in this folder during boot. Startup Folder Location C:\Users\current_user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\ Steps to Add Script 1. Navigate to the Startup folder (you may need to enable "Show hidden files" ...

Read More

Decrypt String from Alphabet to Integer Mapping in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 884 Views

Suppose we have a string s that contains digits ('0' - '9') and '#' characters. We need to map this string to English lowercase characters using a specific encoding scheme ? Characters ('a' to 'i') are represented by ('1' to '9') respectively. Characters ('j' to 'z') are represented by ('10#' to '26#') respectively. For example, if the input is "10#11#12", the output will be "jkab" because 10# maps to 'j', 11# maps to 'k', 1 maps to 'a', and 2 maps to 'b'. Approach We'll solve this by processing the string from right to ...

Read More

Maximize Sum Of Array After K Negations in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 418 Views

Given an array of integers, we need to maximize the sum by negating exactly K elements. We can choose any element and replace it with its negative value, repeating this process K times. The strategy is to first negate all negative numbers (since negating them increases the sum), then handle remaining negations optimally. Algorithm The approach involves these steps: Sort the array to process negative numbers first Negate negative numbers until K operations are exhausted or no negatives remain If K operations remain and K is odd, negate the smallest positive number Return the sum ...

Read More

Non-decreasing Array in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

A non-decreasing array is one where each element is less than or equal to the next element: array[i] nums[i+1] and count them ? If the array has 2 or fewer elements, return True Track violations using a boolean flag For each violation, decide whether to modify nums[i] or nums[i+1] If more than one violation exists, return False Implementation def checkPossibility(nums): if len(nums) nums[i + 1]: # If we already found a violation, return False ...

Read More

Shortest Unsorted Continuous Subarray in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 384 Views

Given an integer array, we need to find the shortest continuous subarray that, when sorted, makes the entire array sorted. For example, in the array [2, 6, 4, 8, 10, 9, 15], the subarray [6, 4, 8, 10, 9] needs to be sorted to make the whole array sorted, so the answer is 5. Approach We compare the original array with its sorted version to identify positions where elements differ. The shortest subarray spans from the first differing position to the last differing position. Algorithm Steps Create a sorted copy of the input array Compare ...

Read More
Showing 1571–1580 of 3,768 articles
« Prev 1 156 157 158 159 160 377 Next »
Advertisements