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
Programming Articles
Page 535 of 2547
Domino Covering Board in Python
Suppose we have two numbers n and m representing a board of size n x m. We also have an unlimited number of 1 x 2 dominos. We have to find the maximum number of dominos that can be placed on the board such that they don't overlap and every domino lies completely within the board. Each domino covers exactly 2 squares, so the maximum number of dominos we can place is limited by the total number of squares divided by 2. Understanding the Problem For a board of size n x m: Total squares ...
Read MoreDetect Voter Fraud in Python
Voter fraud detection involves identifying cases where a voter has cast multiple votes in an election. In Python, we can detect this by checking if any voter ID appears more than once in our voting records. Each vote is represented as [candidate_id, voter_id], where the candidate_id is who they voted for and voter_id uniquely identifies the voter. Problem Statement Given a list of votes where each vote contains [candidate_id, voter_id], we need to determine if any voter has voted more than once. For example, if the input is [[5, 1], [5, 0], [5, 4], [5, 3], ...
Read MoreCounting Number of Dinosaurs in Python
Suppose we have a string called animals and another string called dinosaurs. Every letter in animals represents a different type of animal and every unique character in dinosaurs string represents a different dinosaur. We have to find the total number of dinosaurs in animals. So, if the input is like animals = "xyxzxyZ" dinosaurs = "yZ", then the output will be 3, as there are two types of dinosaurs y and Z. In the animal string there are two y type animals and one Z type animal. Algorithm To solve this, we will follow these steps − ...
Read MoreCount Elements x and x+1 Present in List in Python
Suppose we have a list of numbers called nums, we have to find the number of elements x there are such that x + 1 exists as well. So, if the input is like [2, 3, 3, 4, 8], then the output will be 3 because: 2 has 3 (2+1) in the list 3 has 4 (3+1) in the list (counted twice since 3 appears twice) 4 doesn't have 5 in the list 8 doesn't have 9 in the list Algorithm To solve this, we will follow these steps − Create a ...
Read MoreCell Count After Removing Corner Diagonals in Python
Suppose we have a number n representing the length of an n × n board. We need to remove all cells that are diagonal to one of the four corners and count the remaining cells. In this problem, we identify cells that lie on the main diagonal (top-left to bottom-right) or anti-diagonal (top-right to bottom-left) and mark them as removed. The remaining cells represent our answer. Problem Visualization For n = 4, the board looks like this after removing diagonal cells ? XOOX OXXO OXXO XOOX Here, X represents removed diagonal ...
Read MoreConnell sequence in Python
The Connell sequence is a mathematical sequence that alternates between groups of consecutive odd and even integers, with each group size increasing by one. Understanding this pattern helps us find the nth term efficiently. Understanding the Connell Sequence Pattern The sequence follows this specific pattern ? Take first 1 odd integer: 1 Take next 2 even integers: 2, 4 Take next 3 odd integers: 5, 7, 9 Take next 4 even integers: 10, 12, 14, 16 Continue alternating with increasing group sizes The complete sequence looks like: 1, 2, 4, 5, 7, 9, 10, ...
Read MoreCommon Words in Two Strings in Python
Finding common words between two strings is a frequent programming task. This involves splitting strings into words, handling case-insensitivity, and finding intersections between word sets. For example, if we have s0 = "i love python coding" and s1 = "coding in python is easy", the common words are python and coding, so the count is 2. Algorithm Steps To find common words between two strings, follow these steps: Convert both strings to lowercase for case-insensitive comparison Split each string into a list of words using split() Convert word lists to sets and find their intersection ...
Read MoreColumn Sort of a Matrix in Python
Matrix column sorting involves sorting each column of a matrix independently in ascending order. This is useful for organizing data where each column represents different attributes that need to be ordered separately. Problem Statement Given a matrix, we need to sort each column in ascending order while keeping the column structure intact. Example Input and Output Input Matrix: 11 21 31 6 6 4 1 11 8 Expected Output: 1 6 4 6 11 8 11 21 31 ...
Read MoreCollatz sequence in Python
The Collatz sequence (also known as the 3n+1 problem) is a mathematical sequence where we repeatedly apply rules to a positive integer until it reaches 1. For any positive integer n: If n is even: n = n/2 If n is odd: n = 3n + 1 Continue until n = 1 For example, if n = 13, the sequence is: [13, 40, 20, 10, 5, 16, 8, 4, 2, 1] with a length of 10. Algorithm Steps To find the length of a Collatz sequence ? If num is 0, return ...
Read MoreTotal Distance to Visit City Blocks in Python
Suppose we have a matrix of unique strings representing the city blocks, and another list of strings containing blocks to visit. If we are at block matrix[0][0], then find the total Manhattan distance required to visit every block in order. The Manhattan distance between two points (x1, y1) and (x2, y2) is calculated as |x1 - x2| + |y1 - y2|. Example Problem Consider this city block matrix ? Q B C D E Z G H I Blocks to visit: ["H", "B", "C"] Starting from ...
Read More