Found 10784 Articles for Python

Program to decode a run-length form of string into normal form in Python

Arnab Chakraborty
Updated on 05-Oct-2020 06:29:32

2K+ Views

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"To solve this, we will follow these steps −output := blank stringnum:= blank stringfor each character i in s, doif i ... Read More

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

Arnab Chakraborty
Updated on 05-Oct-2020 06:25:34

203 Views

Suppose we have 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"].To solve this, we will follow ... Read More

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

Arnab Chakraborty
Updated on 05-Oct-2020 06:23:26

598 Views

Suppose we have a number n, we have to check whether every rotation of n is prime or not.So, if the input is like n = 13, then the output will be True, as 13 is prime, 31 is also prime.To solve this, we will follow these steps −n := n as stringdo a loop for size of n times, doif n is not a prime number, thenreturn Falsen := n[from index 1 to end] concatenate first character of nreturn TrueLet us see the following implementation to get better understanding −Example Live Democlass Solution:    def solve(self, n):       ... Read More

Malicious QR Code with QRGen

Ajay yadav
Updated on 29-Sep-2020 11:14:21

727 Views

The QR codes are machine-readable data formats used for anything that needs to be scanned automatically. It is possible to exploit the common vulnerabilities using exploits packed into custom QR codes as it is everywhere, from product packaging to airline boarding passes, etc. Hacker used a tool QRGen that create malicious QR codes to target vulnerable devices. QR code attacks are potent because humans can't read or understand the information contained in a QR code without scanning it, potentially exposing any device used to attempt to decipher the code to the exploit contained within. A human can't spot a malicious ... Read More

Build Your Own Botnet

Ajay yadav
Updated on 29-Sep-2020 11:05:23

7K+ Views

BYOB provides a framework for security researchers and developers to build and operate a basic botnet to deepen their understanding of the sophisticated malware that infects millions of devices every year and spawns modern botnets, in order to improve their ability to develop counter-measures against these threats. It is designed to allow developers to easily implement their own code and add cool new features without having to write a RAT or Command & Control server from scratch.FeaturesNothing Written To The Disk − clients never write anything to the disk - not even temporary files because remote imports allow arbitrary code ... Read More

Length of a Linked List in Python

Arnab Chakraborty
Updated on 23-Sep-2020 07:39:01

6K+ Views

Suppose we have a singly linked list, we have to find its length. The linked list has fields next and val.So, if the input is like [2 -> 4 -> 5 -> 7 -> 8 -> 9 -> 3], then the output will be 7.To solve this, we will follow these steps −count := 0while node is non null, docount := count + 1node:= next of nodereturn countLet us see the following implementation to get better understanding −Example Live Democlass ListNode:    def __init__(self, data, next = None):       self.val = data       self.next = next def ... Read More

Latin Square in Python

Arnab Chakraborty
Updated on 21-Oct-2021 09:37:38

1K+ Views

The Latin square is a matrix that has a special pattern. Let's see different examples to examine the pattern.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 Latin square that you get will be of different size as you notice in the above examples. But, if you carefully observe the above matrices' pattern, you will find out that the last number of the previous row comes as the first element of the next row.That's the pattern ... Read More

Largest product of contiguous digits in Python

Arnab Chakraborty
Updated on 23-Sep-2020 07:34:26

284 Views

Suppose we have two numbers num and k, we have to find the largest product of k contiguous digits in num. We have to keep in mind that num is guaranteed to have >= k digits.So, if the input is like num = 52689762 and k = 4, then the output will be 3024, largest product of 4 consecutive digits is (8*9*7*6) = 3024.To solve this, we will follow these steps −largest := 0cand := 1while (quotient of num/10)^(k-1) > 0, dodigits := (last digit of nums)^kcand := 1while digits > 0, docand := cand * (digits mod 10)if cand ... Read More

Largest Number By Two Times in Python

Arnab Chakraborty
Updated on 23-Sep-2020 07:32:53

166 Views

Suppose we have a list of numbers; we have to check whether the largest number is bigger than the second-largest number by more than two times. As an example, if the list is like [3, 9, 6], then it will return false, as 9 is not bigger than 12 (2 times 6). When the list is [6, 3, 15], it will return true, as 15 is bigger than 12 (2 times 6).To solve this, we will follow these steps −if size of nums < 2, thenreturn Falsep_max := minimum of nums[0] and nums[1]c_max := maximum of nums[0] and nums[1]for i ... Read More

Largest Gap in Python

Arnab Chakraborty
Updated on 23-Sep-2020 07:31:10

1K+ Views

Suppose we have a list of numbers called nums, we have to find the largest difference of two consecutive numbers in the sorted version of nums.So, if the input is like [5, 2, 3, 9, 10, 11], then the output will be 4, as the largest gap between 5 and 9 is 4.To solve this, we will follow these steps −n := sorted list numsans := a new listfor i in range 0 to size of n -2, doinsert n[i+1]-n[i] at the end of ansreturn maximum of ansLet us see the following implementation to get better understanding −Example Live Democlass Solution: ... Read More

Advertisements