Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 129 of 377

A strictly increasing linked list in Python

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

A strictly increasing linked list is one where each node's value is greater than the previous node's value. We need to traverse the list and check if the values are in strictly ascending order. So, if the input is like [2, 61, 105, 157], then the output will be True because each element is greater than the previous one. Algorithm To solve this, we will follow these steps − Define a function solve() that takes the head of the linked list If head.next is null, return True (single node is considered strictly increasing) If head.val ...

Read More

A number and its triple in Python

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

When working with lists of numbers, you might need to check if any number in the list is exactly triple another number. This problem can be solved efficiently using a two-pointer approach after sorting the list. For example, if we have nums = [2, 3, 10, 7, 9], the output should be True because 9 is the triple of 3. Algorithm Steps To solve this problem, we follow these steps ? Sort the list to enable two-pointer technique Initialize two pointers: i = 0 and j = ...

Read More

Ancient Astronaut Theory in Python

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

The Ancient Astronaut Theory problem involves checking if a string follows a custom lexicographic ordering defined by an ancient astronaut dictionary. Given a dictionary string that represents the order of characters, we need to verify if the input string is sorted according to this custom order. For example, if the dictionary is "bdc", then 'b' comes before 'd', and 'd' comes before 'c' in this custom ordering. Problem Understanding Given a dictionary string and an input string, we need to check if the characters in the input string appear in the same order as defined by the ...

Read More

Acronym in Python

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

An acronym is formed by taking the first letter of each word in a phrase. In Python, we can create acronyms by splitting the phrase into words and extracting the first character of each word, excluding common words like "and". Problem Statement Given a string representing a phrase, we need to generate its acronym. The acronym should be capitalized and exclude the word "and". For example, if the input is "Indian Space Research Organisation", the output should be "ISRO". Algorithm To solve this problem, we follow these steps ? Split the string into ...

Read More

3 and 7 in Python

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

Sometimes we need to determine if a positive number can be expressed as a sum of non-negative multiples of 3 and 7. This problem involves checking if n = a×3 + b×7 where a and b are non-negative integers. For example, 13 can be written as 1×7 + 2×3 = 13, so the answer is True. Algorithm The approach is to iterate through all possible multiples of 7 up to n and check if the remainder is divisible by 3 − For each multiple of 7 from 0 to n (step by 7) Check if ...

Read More

3-6-9 in Python

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

The 3-6-9 game is a popular counting game where players replace certain numbers with a special word. In this Python implementation, we create a list from 1 to n, but replace numbers that are multiples of 3 or contain the digits 3, 6, or 9 with the string "clap". Problem Statement Given a number n, construct a list with each number from 1 to n as strings, except when the number is a multiple of 3 or contains the digits 3, 6, or 9 − replace these with "clap". For example, if the input is 20, the ...

Read More

24-hour time in Python

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

Converting 12-hour time format to 24-hour format is a common task in Python programming. The 12-hour format uses AM/PM suffixes, while 24-hour format uses hours from 00 to 23. So, if the input is like "08:40pm", then the output will be "20:40". Algorithm To solve this, we will follow these steps − Extract hour from the time string and apply modulo 12 to handle 12 AM/PM cases Extract minutes from the time string If the suffix is 'p' (PM), add 12 to the ...

Read More

123 Number Flip in Python

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

Suppose we have an integer n, where only digits 1, 2, and 3 are present. We can flip one digit to a 3. The goal is to find the maximum number we can make. So, if the input is like 11332, then the output will be 31332. Approach To solve this, we will follow these steps − Convert the number into a list of digits Iterate through each digit from left to right If we find the first digit that is not '3', change it to '3' Return the modified number If all digits are ...

Read More

Find an integer X which is divisor of all except exactly one element in an array in Python

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

Given an array of numbers, we need to find an integer X that divides all elements except exactly one element. This problem assumes that the GCD of all elements is not 1, meaning there exists a common divisor greater than 1. For example, if the input is [8, 16, 4, 24], the output will be 8 because 8 divides all elements (8, 16, 24) except one element (4). Algorithm Approach The solution uses prefix and suffix GCD arrays to efficiently find the GCD of all elements excluding each position ? Prefix GCD: Store GCD from ...

Read More

Find a string in lexicographic order which is in between given two strings in Python

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

Finding a string that is lexicographically between two given strings is a common problem in string manipulation. Given two strings S and T of the same length, we need to find a string that is lexicographically greater than S and smaller than T. A string S = S1S2...Sn is lexicographically smaller than T = T1T2...Tn if there exists an index i where S1 = T1, S2 = T2, ..., Si-1 = Ti-1, but Si < Ti. Algorithm The approach is to increment the given string S to find the next lexicographically larger string ? Start ...

Read More
Showing 1281–1290 of 3,768 articles
« Prev 1 127 128 129 130 131 377 Next »
Advertisements