Found 10476 Articles for Python

Program to count number of elements are placed at correct position in Python

Arnab Chakraborty
Updated on 05-Oct-2020 06:39:45

366 Views

Suppose we have a list of numbers called nums, we have to find the number of elements that are present in the correct indices, when the list was to be sorted.So, if the input is like [2, 8, 4, 5, 11], then the output will be 2, as the elements 2 and 11 are in their correct positions. The sorted sequence will be [2, 4, 5, 8, 11]To solve this, we will follow these steps −s := sort the list numscount := 0for i in range 0 to size of nums, doif s[i] is same as nums[i], thencount := count ... Read More

Program to check whether we can stand at least k distance away from the closest contacts in Python

Arnab Chakraborty
Updated on 05-Oct-2020 06:38:07

74 Views

Suppose we have a string s and a number k. Now each character in the string is either dot ('.') or 'x', where dot indicates an empty space and 'x' indicates a person. We have to check whether it's possible to choose a position to stand on such that the distance between us and the closest person to us is at least k. (Here the distance between each neighbouring indices is 1).So, if the input is like s = "x...x..", k = 2, then the output will be True, as we can stand at s[2] or s[6].To solve this, we ... Read More

Program to find shortest sublist so after sorting that entire list will be sorted in Python

Arnab Chakraborty
Updated on 05-Oct-2020 06:35:44

233 Views

Suppose we have a list of numbers called nums, we have to find the length of the shortest sublist in num, if the sublist is sorted, then the entire array nums will be sorted in ascending order.So, if the input is like nums = [1, 2, 5, 4, 9, 10], then the output will be 2, as Sorting the sublist [4, 3] would get us [0, 1, 3, 4, 8, 9]To solve this, we will follow these steps −f:= -1, l:= -1lst:= sort the list numsfor i in range 0 to size of nums, doif nums[i] is not same as ... Read More

Program to find shortest string after removing different adjacent bits in Python

Arnab Chakraborty
Updated on 05-Oct-2020 06:33:53

284 Views

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.To solve this, we will follow these steps −stack := a new listfor each c in s, ... Read More

Program to encode a string in normal form to its run-length form in Python

Arnab Chakraborty
Updated on 05-Oct-2020 06:31:52

471 Views

Suppose we have a string s. We have to encode this by using run-length encoding technique. 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.So, if the input is like s = "BBBBAAADDCBB", then the output will be "4B3A2D1C2B"To solve this, we will follow these steps −res := blank stringtmp := first character of scount := 1for i in range 1 to size of s, doif s[i] is not same as tmp, thenres := res concatenate count concatenate ... Read More

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

293 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

703 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

922 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

8K+ 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

Advertisements