Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 193 of 377

Find Tangent at a given point on the curve in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 398 Views

Suppose we have a curve like y = x(A - x), we have to find the tangent at a given point (x, y) on that curve. Here A is an integer number, x and y are also integers.To solve this, we have the check that the given point is on the curve or not, if so, then find the differentiation of that curve, so it will be −$$\frac{\text{d}y}{\text{d}x}=A-2x$$Then put x and y into the dy/dx, then find the tangent using this equation −$$Y-y=-\lgroup\frac{\text{d}y}{\text{d}x}\rgroup*\lgroup X-x \rgroup$$Example#include using namespace std; void getTangent(int A, int x, int y) {    int differentiation = ...

Read More

Add to Array-Form of Integer in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 564 Views

Suppose we have a number in array form. So if the number is say 534, then it is stored like [5, 3, 4]. We have to add another value k with the array form of the number. So the final number will be another array of digits.To solve this, we will follow these steps −Take each number and make them string, then concatenate the stringconvert the string into integer, then add the numberThen convert it into string again, and make an array by taking each digit form the string.ExampleLet us see the following implementation to get better understanding −class Solution(object): ...

Read More

Complement of Base 10 Integer in Python

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

Suppose we have a number in decimal number system. We have to get the complement of the number in binary form, then again change it to decimal and return the result. So if the number is 20, then the binary form will be 10100, the complement will be 01011, this is 11 in decimalTo solve this, we will follow these steps −s := binary string of the number nsum := 0 and num := 1for each element i in s in reverse directionif i = ‘b’, then return sumotherwise when i = ‘0’, then sum := sum + numnum := ...

Read More

Find the closest leaf in a Binary Tree in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 382 Views

Suppose, one binary tree is given. It has leaf nodes at different levels. Another pointer is given, that is pointing to a node. We have to find the distance to the nearest leaf node from the pointed node. Consider the tree is like below −Here leaf nodes are 2, -2 and 6. If the pointer is pointing to node -5, The nearest nodes from -5 will be at distance 1.To solve this, we will traverse the subtree rooted with the given node, and find the closest leaf in the subtree, then store the distance. Now traversing tree starting from the ...

Read More

Pairs of Songs With Total Durations Divisible by 60 in Python

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

Suppose we have a list of songs, the i-th song has a duration of time[i] seconds. We have to find the number of pairs of songs for which their total time in seconds is divisible by 60.So if the time array is like [30, 20, 150, 100, 40], then the answer will be 3. Three pairs will be (3, 150), (20, 100), (20, 40) for all cases the total duration is divisible by 60.To solve this, we will follow these steps −Take a map rem to store remainders. Set ans := 0for all elements i in time −if i is ...

Read More

Palindrome Linked List in Python

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

Suppose we have a linked list. We have to check whether the list elements are forming a palindrome or not. So if the list element is like [1, 2, 3, 2, 1], then this is a palindrome.To solve this, we will follow these steps −fast := head, slow := head, rev := None and flag := 1if the head is empty, then return truewhile fast and next of fast is availableif next of the next of fast is available, then set flag := 0 and break the loopfast := next of the next of fasttemp := slow, slow := next ...

Read More

Path Sum III in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 324 Views

Suppose we have given a binary tree in which each node holds an integer key. We have to find the paths that sum to a given value. The path should start from root to leaf. We have to find the path where the sum is same.If the tree is like [5, 4, 8, 11, null, 13, 4, 7, 2, null, null, 5, 1], and sum is 22, then it will be −The paths are [[5, 4, 11, 2], [5, 8, 4, 5]].To solve this, we will follow these steps −Use the dfs function to solve this problem, the dfs is ...

Read More

Partition Array Into Three Parts With Equal Sum in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 526 Views

Suppose we have an array A of integers, our output will be true if and only if we can partition the array into three non-empty parts whose sum is equal.Formally, we can partition the array if we can find the indexes i+1 < j with (A[0] + A[1] + ... + A[i] is same as A[i+1] + A[i+2] + ... + A[j-1] and A[j] + A[j-1] + ... + A[A.length - 1])So if the input is [0, 2, 1, -6, 6, -7, 9, 1, 2, 0, 1], then the output will be true. Three arrays will be [0, 2, 1], ...

Read More

Shortest Unsorted Continuous Subarray in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 374 Views

Suppose we have an integer array, we need to find one continuous subarray such that, if we only sort that subarray in ascending order, then the whole array will be sorted too. We need to find the shortest such subarray and output its length. So if the array is [2, 6, 4, 8, 10, 9, 15], then the output will be 5. The array will be [6, 4, 8, 10, 9]To solve this, we will follow these steps −res := sort the nums as an arrayans := 0set r as a linked listfor i in range 0 to the length ...

Read More

Find the common nodes in two singly linked list in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 490 Views

Suppose we have two singly-linked lists. We have to find the total number of common nodes in both the singly linked list. So if two lists are like [15, 16, 10, 9, 7, 17], and [15, 16, 40, 6, 9], there are three common nodes.Traverse both lists up to end of the list using two nested loops, for every node in the list, check if it is matched with any node of the second list or not. If a match is found, then increase the counter, and finally return the count.Example#include using namespace std; class Node {    public:   ...

Read More
Showing 1921–1930 of 3,768 articles
« Prev 1 191 192 193 194 195 377 Next »
Advertisements