
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 2144 of 2651

711 Views
Here we will see, how to check whether a number is a palindrome or not. The palindrome numbers are the same in both directions. For example, a number 12321 is a palindrome, but 12345 is not a palindrome.The logic is very straight forward. We have to reverse the number, and if the reversed number is the same as the actual number, then that is a palindrome, otherwise not. Let us see the algorithm to get a better idea.AlgorithmisPalindrome(n) −input − The number noutput − true, if the number is a palindrome, otherwise, falsebegin temp := n rev := ... Read More

732 Views
Here we will see how to check a number is divisible by 5 or not. One simple approach is that if the number mod 5 = 0, then, the number is divisible by 5. But here we will not use / or % operator. To check whether a number is divisible by 5, we have to see the last number is 0 or 5. If that is 0 or 5, the number is divisible by 5, otherwise not. Here we can use some large numbers also as a string to check.Example#include using namespace std; bool isDiv5(string num){ int ... Read More

497 Views
Here we will see one interesting problem to check whether a number is jumbled or not. A number is said to be jumbled if, for every digit, it's neighbor digit differs by max 1. For example, a number 1223 is jumbled, but 1256 is not jumbled.To solve this problem, we have to check if a digit has a neighbor with a difference greater than 1. If such digit is found, then return false, otherwise true.Example Live Demo#include #include using namespace std; bool isJumbled(int number) { if (number / 10 == 0) //for single digit number is is always ... Read More

265 Views
Suppose, we have a number string, we have to find that the number is of given base B or not? If the string is “101110”, b = 2, then the program will return true. If the string is “A8F”, base is 16, it will be true.The approach is very simple. If all of the character is in the range of symbols of the given base, then return true, otherwise false.Example Live Demo#include using namespace std; bool inGivenBase(string s, int base) { if (base > 16) //program can handle upto base 1 return false; ... Read More

96 Views
We have an array A, we have to check whether the array can represent a BST with n levels or not. As the level is , we can construct a tree in following manner. Assume a number is k, value greater than k moves to right side, and less than k moves to left side. Suppose two lists are there: {50, 20, 9, 25, 10}, and {50, 30, 20, 25, 10}The first one is not valid, but the second one is valid.To check this we can either create a BST and check the height, otherwise use array based approach. The ... Read More

2K+ Views
Here we will see, if a matrix is magic square or not, a magic square is a square matrix, where the sum of each row, each column, and each diagonal are same.Suppose a matrix is like below −618753294This is a magic square, if we see, the sum of each row, column and diagonals are 15.To check whether a matrix is magic square or not, we have to find the major diagonal sum and the secondary diagonal sum, if they are same, then that is magic square, otherwise not.Example Live Demo#include #define N 3 using namespace std; bool isMagicSquare(int mat[][N]) { ... Read More

625 Views
Consider we have a 2D array. We have to find if we can get a path from topleft corner to bottom-right corner. The matrix is filled with 0s and 1s. 0 indicates open area, 1 indicates blockage. Note that the top-left corner will always be 1.Suppose a matrix is like below −0001010011000101000000100One path is marked as green, there are some other paths also. So the program will return true, if there is a path, otherwise false.We will solve this problem, by changing all accessible node to -1, First change the value of starting point to -1, then get next value ... Read More

203 Views
Consider we have a string and some queries in set Q. Each query contains a pair of integers i and j. and another character c. We have to replace characters at index i and j with the new character c. And tell if the string is palindrome or not. Suppose a string is like “AXCDCMP”, if we use one query like (1, 5, B), then the string will be “ABCDCBP”, then another query like (0, 6, A), then it will be “ABCDCBA”, this is palindrome.We have to create one query using indices i, j, then replace the characters present at ... Read More

200 Views
Suppose we have an array; we have to check whether given number x is the majority element of that array or not. The array is sorted. One element is said to be majority element, when it appears n/2 times in the array. Suppose an array is like {1, 2, 3, 3, 3, 3, 6}, x = 3, here the answer is true as 3 is the majority element of the array. There are four 3s. The size of the array is 7, so we can see 4 > 7/2.We can count the occurrences of x in the array, and if ... Read More

154 Views
We have two arrays to represent the elements of the BST. If we take elements from that array from left to right, and form the BST, then by taking from both the arrays, we will make the same BST. We have to check whether both are forming the same or not. But the constraint is we cannot make the BST. Suppose two arrays are {2, 4, 1, 3}, and {2, 1, 4, 3}, then if we see, both of these sequences can form same BST.The approach is simple. As we know, the elements of left subtree are smaller than root ... Read More