Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 130 of 377

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 179 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 349 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 225 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

Construct a Binary Tree from Postorder and Inorder in Python

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

Building a binary tree from inorder and postorder traversals is a classic tree reconstruction problem. Given these two traversal sequences, we can uniquely reconstruct the original binary tree by leveraging the properties of each traversal type. 3 9 20 15 7 ...

Read More

Construct a Binary Search Tree from given postorder in Python

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

A Binary Search Tree (BST) can be constructed from its postorder traversal sequence. Since a BST's inorder traversal is always sorted, we can derive the inorder sequence and use both traversals to rebuild the tree. .node-circle { fill: #e8f4fd; stroke: #2196F3; stroke-width: 2; } .node-text { font-family: Arial, sans-serif; font-size: 14px; text-anchor: middle; } .edge-line { stroke: #666; stroke-width: 2; } 3 ...

Read More

Heap in C++ STL - make_heap(), push_heap(), pop_heap(), sort_heap(), is_heap, is_heap_until()

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

A heap is a complete binary tree data structure where parent nodes are either greater than (max heap) or less than (min heap) their children. C++ STL provides several heap operations through the header that work with containers like vectors. Basic Heap Operations make_heap() and front() The make_heap() function converts a range in a container to a heap structure. Use front() to access the largest element in a max heap ? #include using namespace std; int main() { vector heap = {33, 43, 53, 38, 28}; make_heap(heap.begin(), heap.end()); cout

Read More

Check if a number is an Achilles number or not in Python

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

An Achilles number is a number that is powerful but not a perfect power. A powerful number means that for every prime factor p, p² also divides the number. A perfect power is a number that can be expressed as a^b where a and b are positive integers and b > 1. Some examples of Achilles numbers are: 72, 108, 200, 288, 392, 432, 500, 648, 675, 800, 864, 968, 972, 1125. Understanding Achilles Numbers For example, 108 is an Achilles number because: 108 = 2² × 3³ (powerful: both 2² and 3² divide 108) ...

Read More

Check if a number is a Trojan Numbers in Python

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

A Trojan Number is a special type of number that meets two criteria: it must be a strong number but not a perfect power. A strong number is one where every prime factor appears at least twice (squared or higher). For example, 72 = 2³ × 3² is strong because both prime factors (2 and 3) appear at least twice, and it's not a perfect power like 8 = 2³. Understanding Strong Numbers A number is strong when every prime factor appears with an exponent of 2 or more ? from math import sqrt def ...

Read More

Check if a king can move a valid move or not when N nights are there in a modified chessboard in Python

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

Suppose we have an infinite chessboard with the same rules as chess. Given N knights and a king's position, we need to check whether the king is in checkmate or not. The coordinate system is bounded by large values like (-10^9

Read More
Showing 1291–1300 of 3,768 articles
« Prev 1 128 129 130 131 132 377 Next »
Advertisements