Python Articles

Page 663 of 855

Longest Chunked Palindrome Decomposition in python

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

The Longest Chunked Palindrome Decomposition problem asks us to find the maximum number of chunks we can split a string into, where the chunks form a palindromic pattern. This means the first chunk equals the last chunk, the second equals the second-to-last, and so on. For example, given the string "antaprezatepzapreanta", we can decompose it as "(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)" which gives us 11 chunks in palindromic order. Algorithm The approach uses two pointers moving from both ends toward the center ? Use two pointers: start at the beginning and end at the end Build chunks from both ...

Read More

Smallest Sufficient Team in Pyhton

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

The Smallest Sufficient Team problem asks us to find the minimum number of people needed to cover all required skills for a project. Given a list of required skills and people with their respective skills, we need to select the smallest team that collectively possesses all required skills. Problem Understanding A sufficient team is a set of people where every required skill is covered by at least one team member. We represent teams using indices − for example, team [0, 2] means people at positions 0 and 2 in the people array. Algorithm Approach We use ...

Read More

Parsing A Boolean Expression in Python

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

Boolean expression parsing involves evaluating complex logical expressions containing AND, OR, and NOT operations. Python can parse these expressions recursively by breaking them down into smaller components. Boolean Expression Format A boolean expression can be one of the following ? "t" − evaluates to True "f" − evaluates to False "!(expression)" − logical NOT of the inner expression "&(expr1, expr2, ...)" − logical AND of 2 or more expressions "|(expr1, expr2, ...)" − logical OR of 2 or more expressions Algorithm Approach We'll use a recursive approach with the following steps ? ...

Read More

Escape a Large Maze Python

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

In this problem, we need to determine if it's possible to navigate from a source position to a target position in a massive 1 million × 1 million grid while avoiding blocked cells. The key insight is that we can't perform a full BFS/DFS on such a large grid, so we use a clever optimization. Problem Analysis The main challenge is the grid size − searching 1 million × 1 million cells would be too slow. However, if there are only a small number of blocked cells, they can only create a limited "enclosed area". The maximum area ...

Read More

Grid Illumination in Python

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

Grid illumination is a problem where we have an N x N grid with lamps at specific positions. Each lamp illuminates its entire row, column, and both diagonals. We need to answer queries about whether specific cells are illuminated, then turn off lamps in the queried cell and its 8 adjacent neighbors. Problem Understanding Given an N x N grid with lamps at positions specified in the lamps array, each lamp illuminates ? Its entire row (x-axis) Its entire column (y-axis) Both diagonals passing through it For each query (x, y), we check if ...

Read More

Smallest Good Base in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 404 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 795 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 546 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
Showing 6621–6630 of 8,549 articles
« Prev 1 661 662 663 664 665 855 Next »
Advertisements