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 1891 of 2646
355 Views
In this problem, we are given an array of integers and a integers K. our task is to create a program that will find the maximum unique element in every subarray of size K with no duplicates.Let’s take an example to understand the problem, Input −array = {4, 1, 1, 3, 3} k = 3Output −4 3 1Explanation −Sub-array of size 3 Subarray {4, 1, 1}, max = 4 Subarray {1, 1, 3}, max = 3 Subarray {1, 3, 3}, max = 1To solve this problem, one simple method is to run two loops and create subarrays and find distinct ... Read More
400 Views
In this article, we are given an array of integers. Our task is to write a program to calculate the maximum triplet sum in the given array, i.e., find the set of three elements whose sum is maximum. Input Output Scenario Consider the following input and output scenario where we have calculated the sum of each triplet and then returned the maximum sum of the triplet in the array: Input: arr = {4, 6, 1, 2} Output: Maximum triplet sum: 12 Here is an explanation of the above example: All ... Read More
211 Views
In this problem, we are given an array of positive integers and a number k. Our task is to create a program that will find the maximum sum of two nonoverlapping subarrays of the given size(k).So, basically we have two print two non-overlapping (distinct) subarrays that have the maximum sum and are of size k.Let’s take an example to understand the problem, Input −array = {7, 1, 6, 9, 2} , k = 2Output −{7, 1} , {6, 9}Explanation −all subarrays of size 2. {7, 1} : sum = 7+1 = 8 {1, 6} : sum = 1+6 = 7 ... Read More
2K+ Views
Suppose we have a non-empty array of integer numbers. we have to return the kth most frequent elements. So if the elements are [1, 1, 1, 1, 2, 2, 3, 3, 3] and k = 2, then the result will beFormally the function should −Return true if there exists i, j, ksuch that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return false.To solve this, we will follow these steps −num_freq = an empty map, freq_list := an empty mapfor each element i in numsif i is not in num_freq, then num_freq[i] ... Read More
641 Views
Suppose there is an unsorted array. We have to check whether an increasing subsequence of length 3 exists or not in that array.Formally the function should −Return true if there exists i, j, ksuch that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return false.To solve this, we will follow these steps −small := infinity, big := infinityfor each element i in arrayif i
745 Views
Suppose we have a singly linked list, we have to group all odd nodes together followed by the even nodes. Here we are talking about the node position not the value in the nodes. We should try to do it in place. So if the nodes are [1, 22, 13, 14, 25], the result will be [1, 13, 25, 22, 14]To solve this, we will follow these steps −if head is null or the next of head is null, then return headhead1 := head, head2 := next of head, head_beg := next of headwhile next of head2 is nor null ... Read More
187 Views
Suppose we have an array for which the ith element is the price of a given stock on the day i. We have to design an algorithm to find the maximum profit. We may complete as many transactions as we want (So, buy one and sell one share of the stock multiple times). But we have to follow these rules −We may not engage in multiple transactions at the same time (So, we must sell the stock before you buy again).After we sell our stock, we cannot buy stock on next day. (So cool down 1 day)If the input is ... Read More
3K+ Views
Suppose we have an unsorted list of integers. We have to find the longest increasing subsequence. So if the input is [10, 9, 2, 5, 3, 7, 101, 18], then the output will be 4, as the increasing subsequence is [2, 3, 7, 101]To solve this, we will follow these steps −trail := an array of length 0 to length of nums – 1, and fill this with 0size := 0for x in numsi := 0, j := sizewhile i is not jmid := i + (j - i) / 2if trails[mid] < x, then i := mid + 1, ... Read More
3K+ Views
Suppose we have an array nums containing n + 1 integers. The members are in range 1 to n. prove that at least one duplicate number must be there. Assume that there is only one duplicate number, we have to find that duplicate element. So if the array is like [1, 3, 4, 2, 2], then the duplicate element will be 2.To solve this, we will follow these steps −a := nums[0] and b := nums[0]while Truea := nums[nums[a]]b := nums[b]if a = b, then breakptr := nums[0]while ptr is not bptr := nums[ptr]b := nums[b]return ptrLet us see the ... Read More
555 Views
Suppose we have a positive integer n, find the least number of perfect square numbers whose sum is n. So if the number is 13, then the output is 2, as the numbers are 13 = 9 + 4To solve this, we will follow these steps −create one table for dynamic programming, of length n + 1, and fill it with infinitydp[0] := 0for i := 1, when i*i dp(n+1,INF); dp[0] = 0; for(int i =1;i*i