Run-length encoding is a simple compression technique that replaces consecutive identical characters with a count followed by the character. For example, "AAABBC" becomes "3A2B1C". So, if the input is like s = "BBBBAAADDCBB", then the output will be "4B3A2D1C2B". Algorithm To solve this, we will follow these steps − Initialize an empty result string Set tmp to the first character and count to 1 Iterate through the string starting from index 1 If current character differs from tmp, append ... Read More
Suppose we have a string s. The s is a run-length encoded string, we have to find the decoded version of it. As we know, run-length encoding is a fast and simple method of encoding strings. The idea is as follows − The repeated successive elements (characters) as a single count and character. For example, if the string is like "BBBBAAADDCBB" would be encoded as "4B3A2D1C2B". So, if the input is like s = "4B3A2D1C2B", then the output will be "BBBBAAADDCBB" Algorithm To solve this, we will follow these steps ? ... Read More
Suppose we have a rotation group for a string that holds all of its unique rotations. If the input is like "567" then this can be rotated to "675" and "756" and they are all in the same rotation group. Now if we have a list of strings words, we have to group each word by their rotation group, and find the total number of groups. So, if the input is like words = ["xyz", "ab", "ba", "c", "yzx"], then the output will be 3, as there are three rotation groups − ["xyz", "yzx"], ["ab", "ba"], ["c"]. Algorithm ... Read More
In this problem, we need to check if all possible rotations of a given number are prime numbers. A rotation means moving digits from the front to the back or vice versa. So, if the input is like n = 13, then the output will be True, as 13 is prime and its rotation 31 is also prime. Algorithm To solve this, we will follow these steps − Convert the number to string format For each possible rotation of the number: Check if the current rotation is prime If any rotation is not prime, ... Read More
QR codes are machine-readable data formats used across various applications, from product packaging to airline boarding passes. However, these convenient codes can be exploited by attackers who embed malicious payloads into custom QR codes using tools like QRGen. Since humans cannot read QR code content without scanning, malicious codes are difficult to identify before exposure, making QR code attacks particularly effective against vulnerable devices. QRGen is a Python tool that generates malicious QR codes by encoding various exploit payloads. It includes a built-in library of popular exploits, making it valuable for penetration testers auditing QR code scanners and security ... Read More
BYOB (Build Your Own Botnet) is an educational framework designed for security researchers and developers to understand malware behavior and develop countermeasures. This Python-based tool helps create a controlled botnet environment for learning purposes. BYOB Architecture Command & Control Server (server.py) Bot Clients (testbot.py) Target Machines ... Read More
A Latin square is a square matrix where each row and column contains every number from 1 to n exactly once. Let's examine the pattern in different sized Latin squares. Understanding the Pattern Here are examples of Latin squares of different sizes ? 1 2 2 1 1 2 3 3 1 2 2 3 1 1 2 3 4 4 1 2 3 3 4 1 2 2 3 4 1 The key pattern is: the last number of the previous row becomes the first element of the next row. This ... Read More
Finding the largest product of contiguous digits is a common programming problem. Given a number and k, we need to find k consecutive digits that produce the maximum product. Problem Statement Given two numbers num and k, find the largest product of k contiguous digits in num. The number is guaranteed to have at least k digits. For example, if num = 52689762 and k = 4, the output should be 3024 because the largest product of 4 consecutive digits is 8×9×7×6 = 3024. Algorithm Steps To solve this problem, we follow these steps: ... Read More
In this problem, we need to find the largest difference between two consecutive numbers in a sorted list. This is commonly known as finding the "largest gap" in a dataset. For example, if we have the list [5, 2, 3, 9, 10, 11], after sorting it becomes [2, 3, 5, 9, 10, 11]. The consecutive differences are: 1, 2, 4, 1, 1. The largest gap is 4 (between 5 and 9). Algorithm Steps To solve this problem, we follow these steps: Sort the input list in ascending order Calculate the difference between each pair of ... Read More
The knight attack problem checks if any two knights on a chessboard can attack each other. A knight moves in an L-shape: two squares in one direction and one square perpendicular, or vice versa. Problem Understanding Given a binary matrix where 0 represents an empty cell and 1 represents a knight, we need to determine if any two knights are attacking each other. For the input matrix: 00000 01000 00010 The output is True because the knight at position (1, 1) can attack the knight at position (2, 3). Knight ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance