Arnab Chakraborty has Published 3734 Articles

Program to find length of longest sign alternating subsequence from a list of numbers in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 07:18:32

246 Views

Suppose we have a list of numbers called nums, we have to find the length of longest subsequence that flips sign on each consecutive number.So, if the input is like nums = [1, 3, -6, 4, -3], then the output will be 4, as we can pick [1, -6, 4, ... Read More

Program to find length of longest interval from a list of intervals in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 07:16:22

557 Views

Suppose we have a list of intervals where each interval is in form [start, end]. We have to find the longest interval that we can make by merging any number of overlapping intervals.So, if the input is like [[1, 6], [4, 9], [5, 6], [11, 14], [16, 20]], then the ... Read More

Program to find length of longest Fibonacci subsequence from a given list in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 07:14:18

405 Views

Suppose we have a list of strictly increasing positive numbers called nums. We have to find the length of the longest subsequence A (of length minimum 3) such that A[i] = A[i - 1] + A[i - 2] for all i > 1.So, if the input is like nums = ... Read More

Program to find longest number of 1s after swapping one pair of bits in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 07:12:39

579 Views

Suppose we have a binary string s. If we can swap at most one pair of characters in the string, we have to find the resulting length of the longest contiguous substring of 1s.So, if the input is like s = "1111011111", then the output will be 9, as we ... Read More

Program to convert a linked list into a binary search tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 07:11:15

638 Views

Suppose we have a singly linked list where elements are arranged in non-decreasing order, we have to convert it to a height balanced binary search tree. So if the list is like [-10, -3, 0, 5, 9], The possible tree will be like −To solve this, we will follow these ... Read More

Program to find union of two given linked lists in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 07:08:44

500 Views

Suppose we have two sorted linked lists L1 and L2, we have to return a new sorted linked list that is the union of the two given lists.So, if the input is like L1 = [10, 20, 30, 40, 50, 60, 70] L2 = [10, 30, 50, 80, 90], then ... Read More

Program to convert linked list to zig-zag binary tree in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 07:06:45

264 Views

Suppose we have a singly linked list, we have to convert it to a binary tree path using following rules −The head of the linked list is the root.Each subsequent node is the left child of the parent when its value is less, otherwise it will be the right child.So, ... Read More

Program to arrange linked list nodes based on the value k in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 07:04:47

185 Views

Suppose we have a singly linked list and another value k. We have to arrange the nodes so that all nodes whose values are less than k come first, and all nodes whose values are equal to k next, and finally other nodes at last. The constraint is that the ... Read More

Program to find folded list from a given linked list in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 07:00:53

324 Views

Suppose we have a linked list. We have to take the first half of the linked list and fold over the second half then merge the intersecting nodes by taking their sum. Finally, we have to return the resulting head of the linked list.So, if the input is like [5, ... Read More

Program to remove last occurrence of a given target from a linked list in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 06:57:56

435 Views

Suppose we have a singly linked list, and another value called target, we have to remove the last occurrence of target in the given list.So, if the input is like [5, 4, 2, 6, 5, 2, 3, 2, 4, 5, 4, 7], target = 5, then the output will be ... Read More

Advertisements