
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
Found 33676 Articles for Programming

777 Views
Suppose there is a lemonade stand, each lemonade costs $5. Now customers are standing in a queue to buy from the store, and order one at a time.Each customer can buy only one lemonade and pay with either a $5, $10, or $20 bill. We have to must provide the correct change to each customer, so that the net transaction is that the customer pays $5. And at first, we have no change in hand.We have to check whether we can provide every customer with correct change.So, if the input is like [5, 5, 5, 10, 20], then the output ... Read More

682 Views
Suppose we have two strings A and B of lowercase letters; we have to check whether we can swap two letters in A so that the result equals to B or not.So, if the input is like A = "ba", B = "ab", then the output will be True.To solve this, we will follow these steps −if size of A is not same as size of B, thenreturn Falseotherwise when A and B has any element that are not common, thenreturn Falseotherwise when A is same as B and all characters are distinct in A, thenreturn Falseotherwise, count:= 0for i ... Read More

400 Views
Suppose we have a grid we have to find the number of magic square sub-grid into that grid. A magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum.So, if the input is like438495192762then the output will be 1, as the magic square is438951276To solve this, we will follow these steps −Define one set with values: [816357492, 834159672, 618753294, 672159834, 492357816, 438951276, 294753618, 276951438]Define an array offset of size: 9 x 2 := {{-2, -2}, {-2, -1}, {-2, 0}, {-1, -2}, ... Read More

5K+ Views
Suppose there is a rectangle that is represented as a list [x1, y1, x2, y2], where (x1, y1) is the coordinates of its bottom-left corner, and (x2, y2) is the coordinates of its top-right corner. Now two rectangles overlap if the area of their intersection is positive. So, we can understand that two rectangles that only touch at the corner or edges do not overlap.If we have two (axis-aligned) rectangles, we have to check whether they overlap or not.So, if the input is like R1 = [0, 0, 2, 2], R2 = [1, 1, 3, 3], then the output will ... Read More

579 Views
Suppose we have a binary matrix A, this is the representation of an image, we want to flip the image horizontally, after that invert it, and finally return the resulting image. To flip the image horizontally each row of the image will be reversed. And to invert the image each 0 will be replaced by 1, and each 1 will be replaced by 0.So, if the input is like110101000then the output will be100010111To solve this, we will follow these steps −result:= a new listfor each row i in A, doReverse:= reverse row ifor j in range 0 to size of ... Read More

233 Views
Suppose there is a string S of lowercase letters, these letters form consecutive groups of the same character. So, when a string like S is like "abbxxxxzyy" has the groups "a", "bb", "xxxx", "z" and "yy". A group will be a large group when it has 3 or more characters. We would like the starting and ending positions of every large group.So, if the input is like "abcdddeeeeaabbbcd", then the output will be [[3, 5], [6, 9], [12, 14]]To solve this, we will follow these steps −ans := a new listcsum := 0for each a, b in make group of ... Read More

630 Views
In this article, we will learn to calculate the GCD of more than two numbers in Java. We will discuss two approaches, the recursive method and an optimized approach using the Euclidean algorithm. The Greatest Common Divisor (GCD) of two or more integers is the largest integer that divides all the numbers without leaving a remainder. When it comes to an array of numbers, finding the GCD means determining the GCD of all the elements in the array. Problem Statement Given an array of integers, find the GCD of all the elements.Example −Input {7, 49, 177, 105, 119, 42} Output ... Read More

698 Views
Suppose we have a list of points on a plane. We have to find the area of the largest triangle that can be formed by any 3 of the points.So, if the input is like [[0, 0], [0, 1], [1, 0], [0, 2], [2, 0]], then the output will be 2To solve this, we will follow these steps −res := 0N := size of points listfor i in range 0 to N - 2, dofor j in range i + 1 to N - 1, dofor k in range i + 2 to N, do(x1, y1) := points[i], (x2, y2) ... Read More

488 Views
Suppose we have a string S and we have to write the letters of that given string, from left to right into lines. Here each line has maximum width 100 units, and if writing a letter would cause the width of the line to exceed 100 units, that will be written on the next line. We also have an array widths, here widths[0] is the width of 'a', widths[1] is the width of 'b'and so on.We have to find the answers of two questions −How many lines have at least one character from SWhat is the width used by the ... Read More

287 Views
In this article, we will learn two different approaches to computing the focal length of a spherical mirror using Java. While the second method makes use of Object-Oriented Programming (OOP) concepts for a more generic and flexible approach the first method is a simple functional implementation. Finding Focal Length Spherical mirrors play a vital role in optical systems, from telescopes and microscopes to vehicle rearview mirrors. These mirrors, either concave or convex, focus or diverge light, respectively, based on their geometry. The focal length, a key characteristic of spherical mirrors, determines how the mirror bends light.The focal length of a ... Read More