Programming Articles

Page 123 of 2547

Powerful Integers in Python

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

A powerful integer is defined as a number that can be expressed in the form xi + yj where x and y are positive integers, and i, j are non-negative integers. Given two positive integers x and y along with a bound, we need to find all powerful integers less than or equal to the bound. Understanding Powerful Integers For example, with x = 2, y = 3, and bound = 10: 2 = 20 + 30 = 1 + 1 3 = 21 + 30 = 2 + 1 4 = 20 + 31 = ...

Read More

Delete Columns to Make Sorted in Python

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

Given an array of N lowercase letter strings of equal length, we need to find the minimum number of column deletions required to make all remaining columns sorted in non-decreasing order. When we delete columns at specific indices, the remaining characters form new columns. Each remaining column must be sorted for the solution to be valid. Problem Understanding Consider the array ["abcdef", "uvwxyz"] with deletion indices {0, 2, 3}: After deletions: ["bef", "vyz"] Remaining columns: ["b", "v"], ["e", "y"], ["f", "z"] All columns are sorted in non-decreasing order Algorithm The approach involves ...

Read More

DI String Match in Python

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

The DI String Match problem involves creating a permutation based on a pattern string containing "I" (increase) and "D" (decrease). Given a string S of length N, we need to return a permutation of numbers [0, 1, ..., N] that satisfies the increase/decrease pattern. Problem Understanding For a string S containing only "I" and "D" characters: If S[i] is "I", then A[i] < A[i+1] (increasing) If S[i] is "D", then A[i] > A[i+1] (decreasing) For example, with input "IDID", a valid output is [0, 4, 1, 3, 2] because: 0 < 4 (I), ...

Read More

Valid Mountain Array in Python

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

A valid mountain array is an array that rises to a peak and then falls, resembling a mountain shape. To be valid, it must have at least 3 elements, strictly increase to a peak, then strictly decrease. Mountain Array Requirements An array is a valid mountain if it satisfies these conditions: Array size >= 3 There exists a peak index i where: Elements strictly increase: A[0] < A[1] < ... < A[i] Elements strictly decrease: A[i] > A[i+1] > ... > A[length-1] Algorithm Approach We use a two-phase traversal approach: Ascending ...

Read More

Reorder Data in Log Files in Python

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

Suppose we have an array of logs. In that array each entry is a space delimited string of words. The first word in each log is an alphanumeric identifier. Then, there are different types of strings like below − Each word after the id will consist only of lowercase letters; Each word after the id will consist only of digits. We will call these two types of logs as letter-logs and digit-logs respectively. It is guaranteed that each log has at least one word after its id. ...

Read More

Number of Recent Calls in Python

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

The RecentCounter class counts recent requests within a 3000 millisecond time window. When you call ping(t), it returns how many pings occurred in the range [t - 3000, t], including the current ping. Problem Overview We need to implement a class that: Maintains a sliding window of 3000 milliseconds Counts pings within this time range Efficiently removes outdated pings Algorithm Steps To solve this problem, we follow these steps − Initialize the class with an empty queue to store timestamps For each ping(t) call: Remove timestamps older than t - 3000 ...

Read More

Smallest Range I in Python

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

The Smallest Range I problem asks us to find the minimum possible difference between the maximum and minimum values of an array after we're allowed to add any value between -K and K to each element. Given an array A of integers, for each integer A[i] we can choose any x with range [-K, K] and add x to A[i]. After this process, we get array B. We need to find the smallest possible difference between the maximum and minimum values of B. Problem Understanding Let's understand this with an example. If A = [0, 10] and ...

Read More

Groups of Special-Equivalent Strings in Python

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

In Python, finding groups of special-equivalent strings involves understanding that two strings are special-equivalent if we can transform one into the other by swapping characters at even positions with each other, and characters at odd positions with each other. A special-equivalent group is a collection of strings where every pair in the group is special-equivalent, and the group cannot be made larger by adding another string from the array. Understanding Special-Equivalent Strings Two strings are special-equivalent if: Characters at even indices (0, 2, 4, ...) can be rearranged among themselves Characters at odd indices (1, 3, ...

Read More

Projection Area of 3D Shapes

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

When we place cubes on a grid, we can calculate the projection area by viewing the 3D structure from three different angles: top view (xy-plane), front view (yz-plane), and side view (xz-plane). Each projection shows the shadow cast by the cubes onto that plane. Grid: [[1, 2], [3, 4]] 3D View: 1 ...

Read More

Walking Robot Simulation in Python

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

A walking robot simulation problem involves a robot on an infinite grid starting at point (0, 0) facing north. The robot receives commands to turn or move forward while avoiding obstacles. Problem Description The robot can receive three types of commands: -2: Turn left 90 degrees -1: Turn right 90 degrees 1-9: Move forward x units Obstacles are represented as coordinates in an array. If the robot encounters an obstacle, it stops at the previous valid position. We need to find the ...

Read More
Showing 1221–1230 of 25,469 articles
« Prev 1 121 122 123 124 125 2547 Next »
Advertisements