Articles on Trending Technologies

Technical articles with clear explanations and examples

Check if the given number K is enough to reach the end of an array in Python

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

We need to traverse an array and check if we can reach the end with a given number k. The rules are: decrement k by 1 for non-prime numbers, and refill k to its original value when encountering prime numbers. If k becomes 0 or negative and the next element is non-prime, we cannot proceed. Problem Analysis Let's trace through the example: nums = [8, 5, 6, 7, 8], k = 2 nums[0] = 8 (not prime) → k = 1 nums[1] = 5 (prime) → k = 2 (refilled) nums[2] = 6 (not prime) → ...

Read More

Check if the given number is Ore number or not in Python

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

An ore number (or harmonic divisor number) is a positive integer where the harmonic mean of its divisors is an integer. The harmonic mean of divisors is calculated as the number of divisors divided by the sum of reciprocals of all divisors. For example, 28 has divisors [1, 2, 4, 7, 14, 28]. The harmonic mean is 6 ÷ (1/1 + 1/2 + 1/4 + 1/7 + 1/14 + 1/28) = 3, which is an integer. Harmonic Mean Formula H = n / (1/d₁ + 1/d₂ + ... + 1/dₙ) For ...

Read More

Check if the given decimal number has 0 and 1 digits only in Python

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

Sometimes we need to check if a decimal number contains only binary digits (0 and 1). This is useful for validating binary representations or checking if a number can be interpreted as a binary string. So, if the input is like num = 101101, then the output will be True since it contains only 0s and 1s. Algorithm To solve this, we will follow these steps − Extract all digits from the number into a set Remove 0 and 1 from the digits set If the set is empty after removal, return True Otherwise, return ...

Read More

Check if the given array contains all the divisors of some integer in Python

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

Sometimes we need to verify if a given array contains all the divisors of some integer. This problem involves finding divisors of the maximum element and comparing them with the array elements. So, if the input is like nums = [1, 2, 3, 4, 6, 8, 12, 24], then the output will be True as these are all the divisors of 24. Algorithm To solve this, we will follow these steps − Find the maximum element in the array (potential number whose divisors we're checking) Generate all ...

Read More

Check if the given array can be reduced to zeros with the given operation performed given number of times in Python

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

We need to check if an array can be reduced to all zeros by performing a specific operation exactly k times. The operation subtracts the smallest non-zero element from all non-zero elements in the array. Understanding the Problem Let's break down how the operation works ? Operation: Find the smallest non-zero element and subtract it from all non-zero elements Goal: Reduce all elements to zero in exactly k operations Key insight: Each operation eliminates one distinct value from the array Example Walkthrough Consider the array [2, 2, 3, 5] with k = 3 ...

Read More

Check if the frequency of all the digits in a number is same in Python

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

A number is considered balanced when the frequency of all its digits is the same. For example, in the number 562256, each digit (5, 6, and 2) appears exactly 2 times, making it a balanced number. In this article, we'll explore different methods to check if a number is balanced in Python. Using Dictionary to Count Frequencies We can convert the number to a string and use a dictionary to count the frequency of each digit ? from collections import defaultdict def is_balanced(num): number = str(num) ...

Read More

Check if the first and last digit of the smallest number forms a prime in Python

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

Given an array of digits, we need to find the smallest possible number from those digits, then check if numbers formed by the first and last digits are prime. This involves sorting digits to create the minimum number and testing primality. Problem Overview For example, if we have digits = [5, 2, 1, 7], the smallest number is 1257. We then form numbers using first and last digits: 17 and 71, and check if they are prime. Algorithm Steps The solution follows these steps − Count frequency of each digit (0-9) Build the smallest ...

Read More

Check if the elements of stack are pairwise sorted in Python

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

Suppose we have a stack of numbers; we have to check whether values in the stack are pairwise consecutive or not. These pairs can be increasing or decreasing. If the stack has an odd number of values, the top element is left out of a pair. We should retain the original stack content after checking. To solve this problem, we can use basic stack operations: push, pop and check if the stack is empty. Example If the input is like stk = [5, 6, -4, -5, 12, 11, 6, 7, 22], then the output will be True. ...

Read More

Check if the characters of a given string are in alphabetical order in Python

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

Suppose we have a string s. We have to check whether characters in s are in alphabetical order or not. So, if the input is like s = "mnnooop", then the output will be True. Method 1: Using Sorting Approach To solve this, we will follow these steps ? char_arr := a new list from the characters present in s sort the list char_arr return char_arr is same as list of all characters in s then true otherwise false Example def solve(s): char_arr = list(s) ...

Read More

Check if the characters in a string form a Palindrome in O(1) extra space in Python

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

A palindrome reads the same forwards and backwards. When checking if a string forms a palindrome, we often need to ignore non-letter characters and focus only on alphabetic characters. This problem requires solving it in O(1) extra space, meaning we cannot create additional data structures. So, if the input is like s = "ra$5ce58car", then the output will be True, as the letters form "racecar" which is a palindrome. Algorithm We use a two-pointer approach with helper functions to find the next valid letter from both ends ? Use two pointers: left (start) and right ...

Read More
Showing 5731–5740 of 61,299 articles
« Prev 1 572 573 574 575 576 6130 Next »
Advertisements