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
C++ Articles - Page 459 of 719
249 Views
Suppose we have a m x n matrix filled with non-negative integers, find a path from top left corner to bottom right corner which minimizes the sum of all numbers along its path. Movements can only be either down or right at any point in time. So for example, if the matrix is like below131151421The output will be 7, the path will be 1, 3, 1, 1, 1, this will minimize the sumLet us see the steps −a := number of rows, b := number of columnsi := a – 1, j := b - 1while j >= 0matrix[a, j] ... Read More
256 Views
Suppose there is a robot is located at the top-left corner of a n x m grid (n rows and m columns). The robot can only move either down side or right side at any point in time. The robot wants to reach the bottom-right corner of the grid (marked 'END in the diagram below).Some cell in the grid is marked, that will be considered as obstacles. So we have to find how many possible unique paths are there? For example if the grid is like [[0, 0, 0], [0, 1, 0], [0, 0, 0]], then the grid will be ... Read More
762 Views
Suppose there is a robot is located at the top-left corner of a n x m grid (n rows and m columns). The robot can only move either down side or right side at any point in time. The robot wants to reach the bottom-right corner of the grid (marked 'END in the diagram below). So we have to find how many possible unique paths are there? For example if m = 3 and n = 2, then the grid will be like below −RoboENDThe output will be 3, So there are total 3 different ways to reach from start ... Read More
696 Views
Suppose we have a linked list. We have to rotate the list to the right k places. The value of k is not negative. So if the list is like [1, 23, 4, 5, NULL], and k = 2, then the output will be [4, 5, 1, 2, 3, NULL]Let us see the steps −If the list is empty, then return nulllen := 1create one node called tail := headwhile next of tail is not nullincrease len by 1tail := next of tailnext of tail := headk := k mod lennewHead := nullfor i := 0 to len – ktail ... Read More
611 Views
Suppose the set is like [1, 2, 3, ..., n], contains a total of n! unique permutations. By listing and labeling all of the permutations in order, we get these sequence for n = 3: ["123", "132", "213", "231", "312", "321"] So if n and k are given, then return the kth permutation sequence. The n will be between 1 to 9 (inclusive) and k will be between 1 to n! (inclusive). For example if n = 3.Let us see the steps −ans := empty string, define array called candidates of size nfor i in range 0 to n – ... Read More
499 Views
Suppose we have a set of candidate numbers (all elements are unique) and a target number. We have to find all unique combinations in candidates where the candidate numbers sum to the given target. The same number will not be chosen from candidates more than once. So if the elements are [2, 3, 6, 7, 8] and the target value is 8, then the possible output will be [[2, 6], [8]]Let us see the steps −We will solve this in recursive manner. The recursive function is named as solve(). This takes index, an array a, the integer b and another ... Read More
1K+ Views
Suppose we have an expression. The expression has some parentheses; we have to check the parentheses are balanced or not. The order of the parentheses are (), {} and []. Suppose there are two strings. “()[(){()}]” this is valid, but “{[}]” is invalid.To solve this, we will follow these steps −Traverse through the expression until it has exhaustedif the current character is opening bracket like (, { or [, then push into stackif the current character is closing bracket like ), } or ], then pop from stack, andcheck whether the popped bracket is corresponding starting bracket of thecurrent character, ... Read More
6K+ Views
Suppose we have Reverse polish notation and we have to evaluate the value. The reverse polish notation is also known as postfix expression. Here we have to use the stack data structure to solve the postfix expressions.From the postfix expression, when some operands are found, pushed them in the stack. When some operator is found, two items are popped from stack and then the operation is performed in the correct sequence. After that, the result is also pushed in the stack for future use. After completing the whole expression, the final result is also stored in the stack top. So ... Read More
637 Views
Suppose there is a circle, and there are n gas stations on the circle. We have two sets of data like −The amount of gas that every gas stations hasDistance from one gas stations to another.Calculate the first point, from where a car will be able to complete the circle. Assume for 1 unit of gas, the car can go 1 unit of distance. Suppose there are four gas stations, and the amount of gas, and distance from the next gas stations is as like [(4, 6), (6, 5), (7, 3), (4, 5)], the first point from where car can ... Read More
451 Views
Suppose we have one input string, a partitioning of that string is palindrome partitioning, when every substring of the partition is a palindrome. In this section, we have to find the minimum cuts are needed to palindrome partitioning the given string. So if the string is like “ababbbabbababa” Minimum cut to partition as palindrome. Here 3 cuts are needed. The palindromes are: a | babbbab | b | ababaTo solve this, we will follow these steps −n := length of strdefine cut matrix and pal matrix each of order n x nfor i := 0 to n, dopal[i, i] := ... Read More