Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 38 of 377

Smallest Good Base in Python

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

Finding the smallest good base is a mathematical problem where we need to find the smallest base k ≥ 2 such that all digits of number n in base k are 1. For example, 121 in base 3 is 11111, so 3 is a good base for 121. Understanding the Problem If a number n has all digits as 1 in base k with m digits, then: n = 1 + k + k² + k³ + ... + k^(m-1) = (k^m - 1) / (k - 1) We need to find the smallest k ≥ 2 ...

Read More

Strong Password Checker in Python

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

A strong password checker validates if a password meets specific security criteria and calculates the minimum changes needed to make it strong. Python provides several methods to check character types and implement password validation logic. Password Strength Criteria A strong password must satisfy these requirements ? Length between 6 and 20 characters At least one lowercase letter, one uppercase letter, and one digit No three consecutive repeating characters (like "aaa", "PPP", "888") Algorithm Overview The solution handles three cases based on password length ? Too short (< 6 characters): Add characters ...

Read More

Word Search II in Python

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

The Word Search II problem involves finding all words from a dictionary that can be formed in a 2D character board. Each word must be constructed from letters of sequentially adjacent cells (horizontally or vertically neighboring), and the same letter cell cannot be used more than once in a single word. This problem is efficiently solved using a Trie (prefix tree) data structure combined with backtracking. The Trie allows us to prune search paths early when no dictionary word has the current prefix. Algorithm Overview The solution follows these key steps ? Build a Trie ...

Read More

Binary Tree Postorder Traversal in Python

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

Binary tree postorder traversal visits nodes in the order: left subtree, right subtree, then root. This article demonstrates an iterative approach using a stack with node-state pairs to achieve postorder traversal without recursion. -10 9 10 15 7 ...

Read More

Word Break II in Python

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

The Word Break II problem involves breaking a string into valid dictionary words and returning all possible sentence combinations. Given a string and a dictionary of valid words, we need to find all ways to add spaces to form valid sentences. For example, with string "appleraincoat" and dictionary ["app", "apple", "rain", "coat", "raincoat"], we can form: "apple rain coat" and "apple raincoat". Algorithm Approach We use dynamic programming with memoization to avoid redundant calculations ? Create a memoization map to store results for substrings For each position, ...

Read More

Longest Consecutive Sequence in Python

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

The Longest Consecutive Sequence problem asks us to find the length of the longest sequence of consecutive integers in an unsorted array. For example, in the array [100, 4, 250, 1, 3, 2], the longest consecutive sequence is [1, 2, 3, 4] with length 4. Algorithm Approach We use a set-based approach for O(n) time complexity ? Convert the array to a set for O(1) lookup operations For each number, check if it's the start of a sequence (i.e., number-1 is not in the set) If it's a sequence start, count consecutive numbers and track the ...

Read More

Binary Tree Maximum Path Sum in Python

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

The maximum path sum problem asks us to find the path in a binary tree with the largest sum of node values. A path can start and end at any nodes and must follow parent-child connections. The path doesn't need to pass through the root. -10 9 10 15 7 ...

Read More

Wildcard Matching in Python

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

Wildcard pattern matching allows you to match strings using special characters. In wildcard matching, '?' matches any single character and '*' matches zero or more characters. This is useful for file pattern matching, search operations, and text processing. Wildcard Characters '?' − Matches exactly one character '*' − Matches zero or more characters Dynamic Programming Approach We can solve wildcard matching using dynamic programming. The idea is to build a 2D table where dp[i][j] represents whether the first i characters of the string match the first j characters of the pattern. Algorithm Steps ...

Read More

Trapping Rain Water in Python

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

The trapping rain water problem is a classic algorithmic challenge where we calculate how much water can be trapped after raining on an elevation map represented by an array of heights. Each element represents the height of a bar with width 1. ...

Read More

First Missing Positive in Python

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

The First Missing Positive problem asks us to find the smallest missing positive integer from an unsorted array. For example, given the array [4, -3, 1, -1], the result is 2 since 1 is present but 2 is missing. Algorithm Approach We use a cyclic sort approach to solve this efficiently: Add a 0 at the beginning to handle 1-based indexing Place each positive number at its correct index position Scan the array to find the first missing positive Example Implementation Here's the complete solution using cyclic sort ? class Solution: ...

Read More
Showing 371–380 of 3,768 articles
« Prev 1 36 37 38 39 40 377 Next »
Advertisements