Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 554 of 2109
Projection Area of 3D Shapes
When we place cubes on a grid, we can calculate the projection area by viewing the 3D structure from three different angles: top view (xy-plane), front view (yz-plane), and side view (xz-plane). Each projection shows the shadow cast by the cubes onto that plane. Grid: [[1, 2], [3, 4]] 3D View: 1 ...
Read MoreWalking Robot Simulation in Python
A walking robot simulation problem involves a robot on an infinite grid starting at point (0, 0) facing north. The robot receives commands to turn or move forward while avoiding obstacles. Problem Description The robot can receive three types of commands: -2: Turn left 90 degrees -1: Turn right 90 degrees 1-9: Move forward x units Obstacles are represented as coordinates in an array. If the robot encounters an obstacle, it stops at the previous valid position. We need to find the ...
Read MoreBinary Gap in Python
A binary gap is the longest sequence of consecutive zeros that are surrounded by ones on both sides in the binary representation of a positive integer. We need to find the maximum distance between two consecutive 1's in the binary representation. For example, if the input is 22, the binary representation is 10110. There are gaps of length 1 (between positions 1 and 3) and length 2 would be the answer if we count the distance differently. Let's implement this step by step. Algorithm To solve this problem, we follow these steps: Convert the number ...
Read MoreLemonade Change in Python
The lemonade change problem is a classic greedy algorithm challenge. At a lemonade stand where each drink costs $5, customers pay with $5, $10, or $20 bills, and we must provide correct change. Starting with no money, we need to determine if we can serve all customers. Problem Analysis For each customer payment: $5 bill: No change needed, keep the bill $10 bill: Give back one $5 bill as change $20 bill: Give back $15 change (prefer one $10 + one $5, or three $5 bills) Algorithm Approach We use a greedy strategy, ...
Read MoreBuddy Strings in Python
Buddy strings are two strings where you can swap exactly two characters in one string to make it equal to the other string. Given two strings A and B, we need to determine if they are buddy strings. For example, if A = "ba" and B = "ab", we can swap positions 0 and 1 in string A to get "ab", which equals B. So the output will be True. Algorithm To solve this problem, we need to check several conditions: If lengths of A and B are different, return False If A and B ...
Read MoreFlipping an Image in Python
Flipping an image in Python involves two operations: horizontally reversing each row and then inverting the binary values (0 becomes 1, 1 becomes 0). This is commonly used in image processing and computer vision applications. Given a binary matrix representing an image, we need to flip it horizontally and then invert all values ? Input and Expected Output For the input matrix: 110 101 000 The expected output after flipping and inverting: 100 010 111 Algorithm Steps Create an empty result list For each row in the ...
Read MorePositions of Large Groups in Python
Sometimes we need to find positions of consecutive character groups in a string that have 3 or more characters. For example, in the string "abbxxxxzyy", the groups are "a", "bb", "xxxx", "z", and "yy", where only "xxxx" qualifies as a large group. Problem Understanding Given a string of lowercase letters, we need to identify large groups (3+ consecutive identical characters) and return their starting and ending positions as a list of ranges. Approach We'll use Python's itertools.groupby() to group consecutive identical characters, then check if each group has 3 or more characters ? from ...
Read MoreLargest Triangle Area in Python
Given a list of points on a plane, we need to find the area of the largest triangle that can be formed by any 3 of the points. This problem requires checking all possible combinations of three points and calculating their triangle areas. So, if the input is like [[0, 0], [0, 1], [1, 0], [0, 2], [2, 0]], then the output will be 2.0 ...
Read MoreNumber of Lines To Write String in Python
When writing a string onto lines with a maximum width of 100 units, we need to determine how many lines are required and the width used by the last line. Each character has a specific width given in a widths array where widths[0] represents the width of 'a', widths[1] represents 'b', and so on. The problem asks us to find ? How many lines have at least one character from the string What is the width used by the last line Algorithm We follow these steps ? Initialize lines = 1 and ...
Read MoreUnique Morse Code Words in Python
In this problem, we need to find how many unique Morse code representations exist for a given list of words. Each letter maps to a specific Morse code pattern, and words with the same Morse code transformation are considered identical. The International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes. For example, "a" maps to ".-", "b" maps to "-...", "c" maps to "-.-.", and so on. Morse Code Mapping Here is the complete list of Morse code patterns for all 26 letters ? morse_codes ...
Read More