Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1870 of 2650
607 Views
Suppose we have a collection of intervals; we have to find the minimum number of intervals we need to remove to make the rest of the intervals non-overlapping. So if the intervals are [[1, 2], [2, 3], [3, 4], [1, 3]], then the output will be 1, as we have to remove [1, 3] to make all others are non-overlapping.To solve this, we will follow these steps −n := size of arrayif n is 0, then return 0count := 1sort the array based on the end time of the intervalsend := end date of the first intervalfor i in range ... Read More
470 Views
Suppose we have an n-ary tree, we have to return the level order traversal of its nodes' values. The Nary-Tree input serialization is represented in their level order traversal. Here each group of children is separated by the null value (See examples). So the following tree can be represented as [1, null, 3, 2, 4, null, 5, 6]The output will be [[1], [3, 2, 4], [5, 6]]To solve this, we will follow these steps −make one matrix ansif root is null, return ansmake one queue q and insert rootwhile q is not emptysize := size of the queuemake one array ... Read More
2K+ Views
Shuffling an array involves rearranging the elements of the array into a random order. For example, if arr = [1, 2, 3, 4, 5], the output might be [5, 3, 2, 1, 4]. Let's explore different ways to shuffle an array in Python. Following are the various methods to shuffle an array in Python − Using shuffle() method Using permutation() method Using simple() method Shuffling using random indices Fisher-Yates shuffle Algorithm Using shuffle() Method The shuffle() method in ... Read More
499 Views
Suppose we have an unsorted array nums, we have to rearrange it such that nums[0] < nums[1] > nums[2] < nums[3]. So if the input is like [1, 5, 1, 1, 6, 4], then the output will be [1, 4, 1, 5, 1, 6].To solve this, we will follow these steps −make one array x, that has same elements as numssort x arrayi := size of x – 1, j := (size of x – 1) / 2 and n := size of nums arrayfor l in range 0 to n – 1, increase l by 2 in each stepnums[l] ... Read More
940 Views
Suppose we have to implement a basic calculator to evaluate a simple expression string. The expression string will hold only non-negative integers, some operators like, +, -, *, / and empty spaces. The integer division should take the quotient part only.So if the input is like “3+2*2”, then the output will be 7.To solve this, we will follow these steps −define a stack s, i := 0, x := an empty stringfor each character j in sif j is not a blank characterappend j into xs := x, n := length of xwhile i < nif s[i] is ‘/’, thenincrease ... Read More
403 Views
Suppose we have a 2D binary matrix filled with 0's and 1's. We have to find the largest square containing only 1's and return its area. So if the matrix is like −10100101101111110010Then the output will be 4To solve this, we will follow these steps −ans := 0, n := number of rows, c := number of rowsif n is 0, then return 0Create another matrix of order (n x c)for i in range 0 to n – 1for j in range 0 to c – 1m[i, j] := matrix[i, j]ans := maximum of m[i, j] and ansfor j in ... Read More
2K+ Views
Suppose we have an array of n elements, and a positive integer s. We have to find the minimal length of a contiguous subarray, of which the sum is greater or equal to s. If there isn’t one, then return 0 instead. So if the array is like [2, 3, 1, 2, 3, 4] and sum is 7, then the output will be 2. This is the subarray [4, 3] has the minimum length for this case.To solve this, we will follow these steps −ans := 0, n := size of array A, j := 0 and sum := 0for ... Read More
1K+ Views
Suppose we have two integers representing the numerator and denominator of a fraction, we have to find fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. So if the numerator is 2 and denominator is 3, then the output will be “0.(6)”To solve this, we will follow these steps −if numerator is 0, then return 0define one array ansif the numerator < 0 and denominator > 0 or numerator 0 and denominator < 0, then insert negative symbol ‘-’ into the ans arraydivisor := |numerator| and dividend := |denominator|, remainder := divisor mod ... Read More
274 Views
Suppose we have a list, we have to sort this in O(n logn) time using constant space complexity, so if the list is like [4, 2, 1, 3], then it will be [1, 2, 3, 4]To solve this, we will follow these steps −Define a method for merging two lists in sorted, order, that method is merge(), this takes two lists l1 and l2.The sort list method will work like below −if head is null, or next of head is null, then return headslow := head, fast := head, and prev = nullwhile fast is not null and next of ... Read More
922 Views
Suppose we have a linked list like l1 -> l2 -> l3 -> l4 -> … -> l(n-1) -> ln. We have to rearrange this list into the form l1 -> ln -> l2 -> l(n - 1) -> … and so on. Here the constraint is that, we cannot modify the values in the list nodes, only the node itself may be changed. So for example, if the list is like [1, 2, 3, 4, 5], then the output will be [1, 5, 2, 4, 3]To solve this, we will follow these steps −Define a method called reverse to ... Read More