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 1846 of 2650
380 Views
In this tutorial, we will be discussing a program to understand input iterators in C++.Input iterators are one of the five iterators in STL being the weakest and simplest of all. They are mostly used in serial input operations where each value is read one and then the iterator moves to the next one.Example Live Demo#include #include using namespace std; int main(){ vector v1 = { 1, 2, 3, 4, 5 }; //declaring iterator vector::iterator i1; for (i1 = v1.begin(); i1 != v1.end(); ++i1) { //looping over elements via iterator cout
473 Views
Suppose we have an immutable linked list, we have to print out all values of each node in reverse with the help of the following interface −ImmutableListNode − This is an interface of an immutable linked list, we are given the head of the list.We have to use the following functions to access the linked list −ImmutableListNode.printValue() − This will print value of the current node.ImmutableListNode.getNext() −This will return the next node.So if the list is like: [0, -4, -1, 3, -5], then the output will be [-5, 3, -1, -4, 0]To solve this, we will follow these steps −Define ... Read More
212 Views
Suppose we have given two strings s and t of the same length. We want to change s to t. Changing the i-th character of s to i-th character of t will assign cost as |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. We have also given an integer maxCost. We have to find the maximum length of a substring of s that can be changed to be the same as the corresponding substring of t with a cost less than or equal to maxCost.So if the input is like s = “abcd” ... Read More
407 Views
Suppose we have given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string. We can swap the characters at any pair of indices in the given pairs any number of times as we want. We have to find the lexicographically smallest string that s can be changed to after using the swaps. So if the input is like s = “dcab” and pairs = [[0, 3], [1, 2]], then the output will be “bacd”. Exchange s[0] and s[3], s = "bcad", then exchange s[1] ... Read More
246 Views
Suppose we have to write a program to find the n-th ugly number. The Ugly numbers are positive integers which are divisible by a or b or c. So for example, if n = 3 and a = 2, b = 3 and c = 5, then the output will be 4, as the ugly numbers are [2, 3, 4, 5, 6, 8, 9, 10], the third one is 4.To solve this, we will follow these steps −make a method called ok(), this will take x, a, b, c, this will act like below −return (x/a) + (x/b) + (x/c) ... Read More
221 Views
Suppose we have a matrix mat where every row is sorted in non-decreasing order, we have to find the smallest common element in all rows. If there is no common element, then return -1. So if the matrix is like −1234524581035791113579The output will be 5To solve this, we will follow these steps −Define a map m, n := row count of matrix, if n is not 0, then x = column size, otherwise 0for i in range 0 to n – 1for j in range 0 to x – 1if m[mat[i, j]] + 1 = i + 1, then increase ... Read More
890 Views
Suppose we have an infinite chessboard with coordinates from -infinity to +infinity, and we have a knight at square [0, 0]. A knight has 8 possible moves it can make, as shown below. Each move is two squares in a cardinal direction, then one square in an orthogonal direction.We have to find the minimum number of steps needed to move the knight to the square [x, y]. It is guaranteed the answer exists.So if the input is like x = 5 and y = 5, then the output will be 4. This will be like [0, 0] → [2, 1] ... Read More
387 Views
Suppose we have a string s that consists of lower case letters and brackets. We have to reverse the strings in each pair of matching parentheses, starting from the innermost one. And the result should not contain any brackets. So if the input is like "(hel(lowo)rld)", then the output will be "dlrlowoleh", so from the beginning, it is changed like: "(hel(lowo)rld)" → "(helowolrld)" → “dlrowoleh”.To solve this, we will follow these steps −n := size of string, make an array called par whose length is n, define a stack stfor i in range 0 to n – 1if s[i] is ... Read More
264 Views
Suppose we have an array color, in which there are three colors: 1, 2 and 3. We have given some queries. Each query consists of two integers i and c, we have to find the shortest distance between the given index i and the target color c. If there is no solution, then return -1. So if the colors array is like [1, 1, 2, 1, 3, 2, 2, 3, 3], and the queries array is like [[1, 3], [2, 2], [6, 1]], the output will be [3, 0, 3]. This is because the nearest 3 from index 1 is ... Read More
168 Views
Suppose we have a list of phrases, generate a list of Before and After puzzles. Here a phrase is a string that consists of lowercase letters and spaces only. No space will be there at the starting and ending positions. There are no consecutive spaces in a phrase.The before and after puzzles are phrases that are formed by merging two phrases where the last word of the first phrase is the same as the first word of the second phrase. We have to find the Before and After puzzles that can be formed by every two phrases phrases[i] and phrases[j] ... Read More