Suppose, we are asked to implement a queue that can push and pop values at the front, middle, and back.We have to implement a pair of functions to push and pop for all three cases. We have to implement another function that shows the full queue at a given time.So, if the input is likepush_from_back(10)push_from_back(20)push_from_front(30)push_from_middle(40)push_from_front(50)show_queue()pop_from_back()show_queue()pop_from_front()show_queue()pop_from_middle()show_queue(), then the output will be [50, 30, 40, 10, 20[50, 30, 40, 10][30, 40, 10][30, 10]To solve this, we will follow these steps −array := array representation of the queueDefine a function push_from_front() . This will take valueinsert value into array at position 0Define a ... Read More
Suppose, we are given n number of points as (x, y). A vertical area is an area that is extended infinitely along the y-axis. We have to find out the vertical area between two points such that no other point is inside the area and is the widest.So, if the input is like pts = [[10, 9], [11, 11], [9, 6], [11, 9]], then the output will be 1.The areas in red and blue are optimal and there are no points inside them.To solve this, we will follow these steps −sort the list ptsfor i in range 1 to size ... Read More
Suppose there is an array called forbidden, where forbidden[i] indicates that the bug cannot jump to the position forbidden[i], and we also have three values a, b, and x. A bug's home is at position x on the number line. It is at position 0 initially. it can jump by following rules −Bug can jump exactly a positions to the right.Bug can jump exactly b positions to the left.Bug cannot jump backward twice in a row.Bug cannot jump to any forbidden positions given in the array.Bug can jump forward beyond its home, but it cannot jump to positions numbered with ... Read More
Suppose, there is a family that consists of members from different generations. Such as the family has a father, his children, and their grandmother. But births and deaths happen in each family.The eldest member of the family is considered the head. So, when the 'head' member dies, their direct successor or their children becomes the head. We implement three functions, the first one is used when a child is born into the family. The function takes the parent's name and child's name as input and adds them to the record.The second function is used when there is a death. It ... Read More
Suppose there is a Ferris wheel with four cabins and each cabin can contain four passengers. The wheel rotates counter-clockwise, and for each rotation, it costs 'run' amount of money. We now have an array 'cust' that contains n items and each item i signifies the number of people waiting to get into the Ferris wheel before the i-th rotation. To board the wheel, each customer has to pay an amount of money 'board', and that much money is for one anti-clockwise rotation of the wheel. The people waiting in line should not wait if there is any vacant seat ... Read More
Suppose we have a string s with only two characters 's' and 't'. We can delete any number of characters of s to make the string balanced. We can say, s is balanced when there is no pair of indices (i, j) such that i < j and s[i] = 't' and s[j]= 's'. We have to find the minimum number of deletions needed to make s balanced.So, if the input is like s = "sststtst", then the output will be 2 because we can either, remove the characters at indices 2 and 6 ("sststtst" to "sssttt"), or remove the ... Read More
Suppose we have an array called, inventory, where inventory[i] represents the number of balls of the ith color we have initially. We also have a value called orders, which represents the total number of balls that the customer wants. we can sell the balls in any order. In our inventory there are different colored balls, customers want balls of any color. Now the values of the balls are special in nature. Each colored ball's value is the number of balls of that color we have in our inventory. So if we currently have 6 blue balls, the customer would pay ... Read More
Suppose, there are n number of houses of different heights and a parkour artist wants to go from one house to another with help of some bricks and ladders. The heights of the houses are given to us as an array. Each brick is a unit length tall and we are given a handful of those. We can use the ladders and the bricks only once. We have to find out the furthest building the parkour artist can go to.So, if the input is like heights = [5, 8, 7, 6, 2, 3, 1, 4], bricks = 3, ladders = ... Read More
Suppose we have sequence of numbers nums, and another two arrays l and r of size m, these l and r are representing range queries like [l[i], r[i]]. We have to find a Boolean sequence ans, where ans[i] is true when the subarray nums[l[i]], nums[l[i] + 1], ... nums[r[i] - 1], nums[r[i]] can be arranged to generate an arithmetic sequence, otherwise false.A sequence is said to be arithmetic, if it consists of at least two elements, and the difference between every two consecutive elements is the same. For example, some arithmetic sequences are: [2, 4, 6, 8, 10], [5, 5, ... Read More
The angular.isArray() function in AngularJS basically checks if a reference is an Array or not. This method will return True if the reference passed inside the function is an Array type, else it will return False.Syntaxangular.isArray(value)Example − Check if the reference is an Array or notCreate a file "isArray.html" in your Angular project directory and copy-paste the following code snippet. angular.isArray() Welcome to Tutorials Point AngularJS | angular.isArray() ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP