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
Programming Articles - Page 1973 of 3363
576 Views
Suppose we have S and T two strings these are composed of lowercase letters. In S, no letter occurs more than once. S was sorted in some custom order previously. We have to permute the characters of T so that they match the order that S was sorted. More specifically, if x occurs before y in S, then x will occur before y in the returned string.So if the S = “cba” and T = “abcd”, then the output will be “cbad”. Here "a", "b", "c" appear in S, so the order of "a", "b", "c" should be "c", "b", ... Read More
505 Views
Suppose we have two types of shapes, Domino and Tromino. They can be rotated like below −In a tiling, every square must be covered by a tile. Here two tilings are different if and only if there are two 4-directionally adjacent cells on the board such that exactly one of the tilings has both squares occupied by a tile.Given N, then we have to find in how many ways we can tile 2xN board? So if the input is 3, then the output will be 5. So the arrangements can be [XYZ XXZ XYY XXY XYY] and [XYZ YYZ XZZ ... Read More
282 Views
Suppose we have an array nums of integers, we can perform some operations on the array. Here in each operation, we pick any nums[i] and delete it to earn nums[i] amount of points. We must delete every element equal to nums[i] - 1 or nums[i] + 1. Initially the point is 0. We have to find the maximum number of points we can earn by applying such operations. So if the input is like [3, 4, 2], then the output will be 6. So this is because, if we delete 4, we will get 4 points, consequently 3 will also ... Read More
1K+ Views
Suppose we have an array asteroids of integers representing asteroids in a row. Now for each asteroid, the absolute value represents its size, and the sign represents its direction that can be positive or negative for the right and left respectively. Each asteroid moves at the same speed.We have to find the state of the asteroids after all collisions. When two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.So if the input is like [5, 10, -5], then output will be [5, ... Read More
190 Views
Suppose in the world of Dota2, there are two parties − The Radiant and also the Dire. The Dota2 senate consists of senators coming from two parties. Now the senate wants to form a choice a few change within the Dota2 game. The voting for this alteration may be a round-based procedure. In each round, each senator can exercise one among the two rights −Ban one senator's right − A senator can make another senator lose all his rights during this and every one the subsequent rounds.Announce the victory − If this senator found the senators who still have rights ... Read More
306 Views
Suppose there is a store, there are some items to sell. Each item has some price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price. So we have the list of prices, a set of special offers, and the number we need to buy for each item. The task is to find the lowest price we have to pay for exactly certain items as given, where we could make optimal use of the special offers.Here each special offer is represented in the form of an array, ... Read More
330 Views
Suppose on a single threaded CPU, we execute some functions. Now each function has a unique id between 0 and N-1. We will store logs in timestamp order that describe when a function is entered or exited.Here each log is a string written this format: "{function_id}:{"start" | "end"}:{timestamp}". For example, if the string is like "0:start:3" this means that the function with id 0 started at the beginning of timestamp 3. "1:end:2" means the function with id 1 ended at the end of timestamp 2. A function's exclusive time is the number of units of time spent in this function.So ... Read More
397 Views
We're given two singly linked lists, where each node stores one digit of a number. The digits are arranged from left to right, just like how we normally write numbers. For example: 7 -> 2 -> 4 -> 3 represents the number 7243. Our task is to add these two numbers and return the sum as a new linked list in the same (left-to-right) order. The input number can contain zeroes at the start, but in the output, there should not be any leading zeros. Let's understand this with a diagram given below - Scenario 1 Input: List 1 ... Read More
251 Views
Suppose we have a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. We have to find the maximum result of ai XOR aj, where 0 ≤ i, j < n. So if the input is like [3, 10, 5, 15, 2, 8], then the output will be 28. The max result will be 5 XOR 25 = 28.To solve this, we will follow these steps −Define insertNode(), this will take val and headcurr := headfor i in range 31 to 0bit := val / (2^i) AND 1if child[bit] of curr is null, ... Read More
864 Views
Suppose we have an array of integers with possible duplicates, we have to pick the index randomly of a given target number. We can assume that the given target number must exist in the array. So if the array is like [1, 2, 3, 3, 3], then pick(3), may return 2, 3, 4 randomly.To solve this, we will follow these steps −ret := - 1, cnt := 1for i in range 0 to size of vif v[i] = target, thenif random number mod cnt = 0, then ret = icnt := cnt + 1return retExample (C++)Let us see the following ... Read More