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 532 of 2547
Program to find shortest string after removing different adjacent bits in Python
Suppose we have a binary string s, we can delete any two adjacent letters if they are different. Finally, we have to find the length of the smallest string that we can get if we are able to perform this operation as many times as we want. So, if the input is like s = "1100011", then the output will be 1, as after deleting "10" we get "10011", then again delete "10", it will be "011", then delete "01", it will have left "1". Algorithm Approach To solve this, we will follow these steps − ...
Read MoreProgram to encode a string in normal form to its run-length form in Python
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 MoreProgram to decode a run-length form of string into normal form in Python
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 MoreProgram to find how many distinct rotation groups are there for a list of words in Python
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 MoreProgram to check whether every rotation of a number is prime or not in Python
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 MoreMalicious QR Code with QRGen
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 MoreBuild Your Own Botnet
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 MoreLatin Square in Python
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 MoreLargest product of contiguous digits in Python
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 MoreLargest Gap in Python
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