Arnab Chakraborty has Published 4293 Articles

Palindrome Linked List in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 27-Apr-2020 08:50:56

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, ... Read More

Print Immutable Linked List in Reverse in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 31-Mar-2020 09:19:35

464 Views

Suppose we have an immutable linked list, we have to print out all values of each node in reverse with the help of the following interface −ImmutableListNode − This is an interface of an immutable linked list, we are given the head of the list.We have to use the following ... Read More

Get Equal Substrings Within Budget in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 31-Mar-2020 09:16:56

197 Views

Suppose we have given two strings s and t of the same length. We want to change s to t. Changing the i-th character of s to i-th character of t will assign cost as |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. ... Read More

Smallest String With Swaps in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 31-Mar-2020 09:15:52

399 Views

Suppose we have given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string. We can swap the characters at any pair of indices in the given pairs any number of times as we want. ... Read More

Remove K Digits in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 31-Mar-2020 08:38:57

735 Views

Suppose we have a non-negative integer num that is represented as a string, we have to remove k digits from the number so that the new number is the smallest possible. So if the input is like “1432219” and k = 3, then the result will be “1219”.To solve this, ... Read More

Minimum Cost Tree From Leaf Values in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 05-Mar-2020 07:33:55

436 Views

Suppose we have an array arr of positive integers, consider all binary trees such that −Each node has either 0 or 2 children;The values of arr array correspond to the values of each leaf in an inorder traversal of the tree.The value of each non-leaf node is equal to the ... Read More

Delete Nodes And Return Forest in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 05-Mar-2020 07:26:02

260 Views

Suppose we have the root of a binary tree, each node in the tree has a unique value. After removing all nodes with a value in to_delete, we are left with a forest. We have to find the roots of the trees in the remaining forest. So if the input ... Read More

Filling Bookcase Shelves in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 05-Mar-2020 07:15:01

614 Views

Suppose we have a sequence of books − Here the i-th book has thickness books[i][0] and height books[i][1]. If we want to place these books in order onto bookshelves that have total width shelf_width. If we choose some of the books to place on this shelf (such that the sum ... Read More

Path With Maximum Minimum Value in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 05-Mar-2020 07:11:48

474 Views

Suppose we have a matrix A of integers with R rows and C columns, we have to find the maximum score of a path starting from [0, 0] and ending at [R-1, C-1]. Here the scoring technique will be the minimum value in that path. For example, the value of ... Read More

Smallest Subsequence of Distinct Characters in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 05-Mar-2020 07:02:11

200 Views

Suppose we have a text, we have to find the lexicographically smallest subsequence of text that contains all the distinct characters of text exactly once. So if the input is like “cdadabcc”, then the output will be “adbc”.To solve this, we will follow these steps −Define a stack st, two ... Read More

Advertisements