Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 41 of 377

3 and 7 in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 410 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 992 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 431 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 206 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 323 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

Find a number which give minimum sum when XOR with every number of array of integer in Python

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

Given an array of integers, we need to find a number X such that the sum of XOR operations between X and each array element is minimized. The key insight is to analyze each bit position independently and choose the bit value that minimizes the total XOR sum. Algorithm Approach For each bit position, we count how many numbers have that bit set. If more than half the numbers have a bit set at position i, then setting that bit in X will minimize the XOR sum for that position. Step-by-Step Solution Here's how the algorithm ...

Read More

Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes in Python

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

Given two sorted linked lists, we need to construct a new linked list that represents the maximum sum path from start to end. We can switch between lists only at common nodes (nodes with the same value). The algorithm compares segments between common nodes and chooses the path with the higher sum. This creates an optimal path that maximizes the total sum. Example If we have lists [6, 8, 35, 95, 115, 125] and [5, 8, 17, 37, 95, 105, 125, 135], the common nodes are 8, 95, and 125. We compare segment sums between these points ...

Read More

Construct a distinct elements array with given size, sum and element upper bound in Python

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

Creating an array with distinct elements that has a specific size, sum, and maximum element value is a common algorithmic problem. We need to construct an array where all elements are distinct, within bounds, and sum to the target value. Problem Understanding Given three parameters: N: Size of the array SUM: Required sum of all elements K: Upper bound for any element in the array We need to find an array of N distinct elements where no element exceeds K and the total sum equals SUM. If impossible, return -1. Algorithm Approach The ...

Read More

Construct a DataFrame in Pandas using string data in Python

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

Pandas DataFrames can be constructed from various data sources including CSV files. You can also create DataFrames directly from string data by using StringIO to simulate file-like input. The StringIO wrapper from the io module allows us to treat string data as if it were being read from a file, making it compatible with pandas' CSV reading functions. Example Let us see how to construct a DataFrame using semicolon-separated string data − import pandas as pd from io import StringIO str_data = StringIO("""Id;Subject;Course_Fee 10;DBMS;3000 11;Basic Maths;2000 ...

Read More
Showing 401–410 of 3,768 articles
« Prev 1 39 40 41 42 43 377 Next »
Advertisements