Yaswanth Varma

Yaswanth Varma

307 Articles Published

Articles by Yaswanth Varma

Page 2 of 31

Check if any interval completely overlaps the other in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 2K+ Views

In many programming problems, intervals are used to represent ranges such as time periods, numeric spans, etc. An interval is typically represented as a pair of numbers (start, end) where start ≤ end. What is Complete Interval Overlap? Complete overlap occurs when one interval fully contains another. For intervals X = (a1, a2) and Y = (b1, b2), X completely overlaps Y when a1 ≤ b1 and a2 ≥ b2. This means the entire range of Y lies within X. .label { ...

Read More

Check if any anagram of a string is palindrome or not in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 649 Views

An anagram is a rearrangement of the characters of a word or phrase to generate a new word, using all the original characters exactly once. For example, thing and night are anagrams of each other. A palindrome is a word or phrase that reads the same forward and backward, like madam or racecar. In this article, we'll check if any anagram of a string can form a palindrome. The key insight is that for a string to have a palindromic anagram, at most one character can have an odd frequency. Algorithm Logic For a palindrome to be ...

Read More

Check if an array represents Inorder of Binary Search tree or not in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 655 Views

The Binary Search Tree (BST) is a widely used data structure that maintains elements in a sorted hierarchical order. Each node in the BST follows a specific property: The values in the left subtree are always less than the current node value. The values in the right subtree are always greater than the current node value. In this article, we will learn how to check if an array represents the inorder traversal of a BST in Python. Understanding BST Inorder Traversal Inorder traversal is a common ...

Read More

Check if an array can be divided into pairs whose sum is divisible by k in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 350 Views

Given an array of integers and a number k, we need to determine whether it's possible to divide the entire array into pairs such that the sum of every pair is divisible by k. For example, with array [2, 4, 1, 3] and k = 5: Pair (2, 3) → 2 + 3 = 5 (divisible by 5) Pair (4, 1) → 4 + 1 = 5 (divisible by 5) Result: True (all pairs sum to multiples of k) Algorithm The key insight is that for two numbers to sum to a multiple of ...

Read More

Check if all bits of a number are set in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 589 Views

In computers, data is stored in the binary form, which uses the two digits 0 and 1. Each digit in this format is known as a bit. In this article, we are going to check if all bits of a number are set in Python. A bit is said to be set if the binary representation of every bit is 1. Let's look at some scenarios to understand this better: Scenario 1 Input: 3 Binary: 11 Output: True Explanation: All bits are 1. Scenario 2 Input: 6 Binary: 110 Output: False ...

Read More

Calculate difference between adjacent elements in given list using Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 1K+ Views

Calculating the difference between adjacent elements in a list is a common task in data analysis. Python provides several efficient approaches to solve this problem using list comprehension, loops, or built-in functions. Problem Definition Given a list, we need to calculate the difference between each adjacent pair of elements (next element minus current element). The result will have one fewer element than the original list. Example Scenario Input: [10, 15, 12, 18] Output: [5, -3, 6] Explanation: 15 - 10 = 5 12 - 15 = -3 18 - 12 = 6 ...

Read More

Alternate element summation in list (Python)

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 1K+ Views

The given task is to perform an alternate summation on a Python List. For example, adding the elements at even indices (0, 2, 4) or odd indices (1, 3, 5), depending on the requirement. This means we need to add every other element from the given list. Let us see an input scenario − Scenario Input: [11, 22, 33, 44, 55] Output: 99 Explanation: Here, we are going to add the elements at the even indices by using the slicing [::2]. Using sum() with List Slicing The alternate element summation in a list can ...

Read More

Analyzing Census Data in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 894 Views

Census data is information collected by the government to understand population characteristics including age, gender, education, and housing. This data helps governments understand current scenarios and plan for the future. In this article, we will learn how to analyze census data in Python using libraries like pandas, numpy, and matplotlib. Sample Census Dataset We'll use sample census data with the following structure: age ...

Read More

Alternate range slicing in list (Python)

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 985 Views

Slicing is used to extract a portion of a sequence (such as a list, tuple, or string) or other iterable objects. Python provides a flexible way to perform slicing using the slice notation with optional start, stop, and step parameters. Syntax list[start:stop:step] What is Alternate Range Slicing? Alternate range slicing retrieves elements from a list by skipping elements at a fixed interval using the step parameter. For example, if we want every second element from a list, we set step=2. Basic Alternate Slicing Example 1: Every Second Element Extract every second ...

Read More

Anagram Substring Search using Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 469 Views

An anagram is a rearrangement of the characters of a word or a phrase to generate a new word, using all the original characters exactly once. For example, thing and night are anagrams of each other. An anagram substring search involves finding all substrings in a text that are anagrams of a given pattern. This means we need to find substrings that contain the same characters as the pattern, regardless of their order. Problem Statement Given two strings text and pattern, find all starting indices of substrings in the text that are anagrams of the pattern. ...

Read More
Showing 11–20 of 307 articles
« Prev 1 2 3 4 5 31 Next »
Advertisements