Python Articles

Page 639 of 855

Program to find how many distinct rotation groups are there for a list of words in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 358 Views

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

Program to check whether every rotation of a number is prime or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 776 Views

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

Malicious QR Code with QRGen

Ajay yadav
Ajay yadav
Updated on 25-Mar-2026 1K+ Views

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

Build Your Own Botnet

Ajay yadav
Ajay yadav
Updated on 25-Mar-2026 9K+ Views

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

Latin Square in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 2K+ Views

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

Largest product of contiguous digits in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 385 Views

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

Largest Gap in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

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

Knights' Attack in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 370 Views

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

K and -K in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 855 Views

In Python, finding the largest number k where both k and -k exist in a list is a common programming problem. This means we need to find pairs of numbers that are additive inverses of each other. So, if the input is like [-5, 2, 9, -6, 5, -9], then the output will be 9 because both 9 and -9 exist in the list. Algorithm Approach To solve this problem, we follow these steps: Create L1: a list of non-negative elements (≥ 0) from nums Create L2: a list of non-positive elements (≤ 0) from ...

Read More

Remove One to Make Average k in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 221 Views

Suppose we have a list of numbers called nums and an integer k, we have to check whether we can remove exactly one element from the list to make the average equal to exactly k. Now we have to keep in mind that, there are some constraints − 2 ≤ n ≤ 1, 000 where n is number of elements of nums list nums[i], k ≤ 1, 000, 000 So, if the input is like [5, 3, 2, 4, 6, 10], k = 4, then the output will ...

Read More
Showing 6381–6390 of 8,546 articles
« Prev 1 637 638 639 640 641 855 Next »
Advertisements