
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 882 of 2650

2K+ Views
Suppose we have to design a system that manages the reservation state of n seats. The seats are numbered from 1 to n. So we have to implement the SeatReserveManager class, with these functions −Constructor that takes n as input and initializes the object that will manage n seats numbered from 1 to n. Initially all seats are available.reserve(), this will fetch the smallest-numbered unreserved seat, then reserves it, and returns its number.unreserve(seatNumber), this will unreserve one reserved seat with the given seatNumber.So, if the input is likeobj = SeatReserveManager(7)obj.reserve()obj.reserve()obj.reserve()obj.unreserve(2)obj.unreserve(5)obj.reserve()obj.reserve()then the output will be 1, 2, 3, 2, 5, initially ... Read More

254 Views
Suppose we have two strings s and t. These two strings are K-similar if we can swap the positions of two letters in s exactly K times so that the resulting string is t. So, we have two anagrams s and t, we have to find the smallest K for which s and t are K-similar.So, if the input is like s = "abc" t = "bac", then the output will be 1.To solve this, we will follow these steps −Define a function neighbors() . This will take new_datafor each index i and value c in new_data, doif c is ... Read More

483 Views
Suppose we have an array nums and another value goal. We want to select a subsequence of nums such that the sum of its elements is the nearest to goal. So in other words, if the sum of the subsequence's elements is s, then we want to minimize the absolute difference |s - goal|.So we have to find the minimum possible value of |s - goal|. So, if the input is like nums = [8, -8, 16, -1] goal = -3, then the output will be 2 because select the subsequence [8, -8, -1], with a sum of -1. The ... Read More

650 Views
Suppose we have a string s with only English vowels, we have to find the length of the longest beautiful substring of s. If we cannot find such substring then, return 0. A string is said to be beautiful if it satisfies the following conditions −Each of the 5 vowels must appear at least once in it.Letters must be sorted in alphabetical sequenceSo, if the input is like s = "aaioaaaaeiiouuooaauu", then the output will be 10 because the substring is "aaaaeiiouu" which is beautiful.To solve this, we will follow these steps −vowels := a list of all vowels ['a', ... Read More

645 Views
Suppose we have an array nums and another value k. In one operation, we can select an index of nums and increase the element at that index by 1. We have to find the maximum possible frequency of an element after performing at most k number of operations.So, if the input is like nums = [8, 3, 6], k = 9, then the output will be 3 because we can update 3 by 5, 6 by 2, to make it [8, 8, 8] so after 7 operations we have maximum frequency 3.To solve this, we will follow these steps −sort ... Read More

681 Views
Suppose we have an array costs with n elements, where costs[i] is the price of the ith ice cream bar in coins. We initially have c number coins to spend, and we want to buy as many ice cream bars as possible. We have to find the maximum number of ice cream bars we can buy with c coins.So, if the input is like costs = [3, 1, 4, 5, 2], c = 10, then the output will be 4 because we can buy ice cream bars at indices 0, 1, 2, 4 for a total price of 3 + ... Read More

294 Views
Suppose we have an array which is presorted called nums of size n and also have one value b. We want to perform the following query n times −Search for a non-negative value k < 2^m such that XOR of all elements in nums and k is maximized. So k is the answer to the ith query.Remove the last element from the current array nums.We have to find an array answer, where answer[i] is the answer to the ith query.So, if the input is like nums = [0, 1, 1, 3], m = 2, then the output will be [0, ... Read More

222 Views
Suppose we have one sequence like X_1, X_2, ..., X_n is fibonacci-like if −n >= 3X_i + X_i+1 = X_i+2 for all i + 2 last, thencome out from loopreturn bestExampleLet us see the following implementation to get better understanding −from collections import Counter def solve(A): sA = set(A) last = A[-1] B = Counter() best = 0 for i in reversed(range(len(A))): a = A[i] for b in A[i+1:]: c = a+b if c in sA: ... Read More

823 Views
Suppose we have an array called nums and another value k. We have to find the number of nice sub-arrays. A subarray is said to be nice subarray if there are k odd numbers on it.So, if the input is like nums = [1, 1, 2, 1, 1], k = 3, then the output will be 2 because there are two subarrays [1, 1, 2, 1] and [1, 2, 1, 1].To solve this, we will follow these steps −odd_i := a new listfor i in range 0 to size of nums - 1, doif nums[i] mod 2 is same as ... Read More

453 Views
Suppose we have two positive valued arrays nums1 and nums2, of same size. The absolute sum difference of these two arrays is the sum of |nums1[i] - nums2[i]| for each 0 [2, 2, 6], orReplace the element at index 1 with the element at index 2: [2, 8, 6] => [2, 6, 6].Both of them get a sum difference of |2-3| + (|2-4| or |6-4|) + |6-6| = 3.To solve this, we will follow these steps −if nums1 is same as nums2, thenreturn(0)minn_diff := -infinityind := -1for i in range 0 to size of nums1 - 1, doif |nums1[i]-nums2[i]| ... Read More