Found 34484 Articles for Programming

Encrypt the string

Prabhdeep Singh
Updated on 26-Jul-2023 10:29:46

1K+ Views

Encryption is the technique to change the data by using some techniques or certain steps so it changes to another information or the previous information cannot be gathered from it directly. For encryption, we have to follow certain steps that are fixed for a particular type of encryption. In this problem, we will be given a string and we have to encrypt it by following the given steps − First, we have to get all the substring that contains the same characters and replace that substring with a single character followed by the length of the substring. Now, change ... Read More

Count of 3 length strings using given characters containing at least 2 different characters

Prabhdeep Singh
Updated on 26-Jul-2023 10:27:26

70 Views

Three integers are given to us ‘a’, ‘b’, and ‘c’ represents the frequency of the three different characters ‘A’, ‘B’, and ‘C’. We have to find the number of different strings that can be formed by using these characters and there must be at least two different characters present in the string formed. We will see two approaches for this problem one is the naive approach and another is the mathematical approach. Sample Examples Input 1: a = 3, b = 2, c = 4 Output: 3 Explanation We can create three strings ‘ABC’, ‘ABC’, ... Read More

Maximize 0s to be flipped in a given Binary array such that there are at least K 0s between two 1s

Prabhdeep Singh
Updated on 26-Jul-2023 10:11:07

79 Views

A Binary Array is a special type of array that only contains the numbers 0 and 1. In this problem, we have given a binary array and integer K. Our task is to count the maximum number of 0’s that can be flipped to 1 in a given binary array such that there are at least K 0’s between two 1s. Sample Examples Input 1: arr[] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, K = 2 Output 1: yes Explanation The 3rd and 6th indexes of the above ... Read More

Print all Balanced Brackets Strings that can be formed by replacing wild card ‘?’

Prabhdeep Singh
Updated on 26-Jul-2023 10:08:53

123 Views

Balanced Brackets mean if we have a string of brackets then each open bracket has a corresponding close bracket and the pair of brackets is properly nested. The size of the string should be ab even number. In this problem we have given a string of the brackets that also contain the character ‘?’ and our task is to form every possible balanced bracket string by replacing the ‘?’ to appropriate brackets. In our given string only parentheses ‘(‘ and ‘)’ brackets are used. Sample Examples Input 1: str = “()(?)?” Output 1: ()(()) Explanation Only one balanced ... Read More

Check if the end of the given Binary string can be reached by choosing the jump value in between the given range

Prabhdeep Singh
Updated on 26-Jul-2023 10:00:09

34 Views

A binary string is a string that contains only two different types of characters that are 0 and 1. We are given a binary string and two integers L and the R. We can make the jump of size between ‘L’ and ‘R’ length both inclusive and only from the index where the value of the string is ‘0’. We have to start from the Zeroth index and find out whether we can reach the last index or not. Sample Examples Input1: string str = “01001110010” int L = 2, R = 4 Output: Yes, we can reach the ... Read More

Minimum K such that every substring of length at least K contains a character c

Prabhdeep Singh
Updated on 25-Jul-2023 15:21:05

125 Views

A string is given in this problem and we have to find a minimum length ‘k’ such that all the substrings of the given string of length k contains at least one common character. We will see three approaches for this problem, one the naive approach to find all the substrings, another one is the binary search approach and third is by using the minimum difference approach. Sample Example string str = “efabc” Output: 3 Explanation For the substrings of length 1 and 2 it is not possible to contain the same character for example substring ‘ef’ and ‘bc’ ... Read More

Kth Character After Replacing Each Character of String by its Frequency Exactly X Times

Prabhdeep Singh
Updated on 25-Jul-2023 15:18:22

109 Views

In this problem we have given a string ‘str’, integer K, and integer X. That string ‘str’ contains only integers in the range between 1 to 9. We have to perform an operation over the string exactly X times. Operation is that every time we have to replace a character of string by itself its frequency times. Here the frequency means the number or the value of the character of the string. Our task is to return the kth character after doing a given operation exactly X times. Sample Examples Input 1: str = “1231”, K = 5, X = ... Read More

Convert given Strings into T by replacing characters in between strings any number of times

Prabhdeep Singh
Updated on 25-Jul-2023 15:16:19

58 Views

Convert string means we have to make the same as a given string on the basis of a given condition. In this problem, we have given an array of strings ‘arr’ and string ‘T’ of size ‘M’. our task is to check if is it possible to make all the string present in an array as same as the given string T by removing any character from a string of an array ( arr[i] ) and inserting that character into any index of another string of the array ( arr[j] ). We can do this any number of times. If ... Read More

Pretty Printing XML in Python

Priya Mishra
Updated on 25-Jul-2023 11:32:53

5K+ Views

When dealing with XML data in Python, ensuring its readability and structure can greatly enhance code comprehension and maintainability. Pretty printing XML, or formatting it with proper indentation and line breaks, is a valuable technique for achieving these goals. In this article, we explore two different methods to pretty print XML using Python: xml.dom.minidom and xml.etree.ElementTree. By understanding these approaches, developers can effectively present XML data in an organized and visually appealing manner, facilitating easier analysis and manipulation. How to Pretty print XML in Python? Below are the two methods using which we can perform pretty printing in Python ... Read More

Pretty print Linked List in Python

Priya Mishra
Updated on 25-Jul-2023 11:27:06

934 Views

Printing a linked list in a well-formatted and readable manner is essential for understanding and debugging purposes which can easily be done using the Pretty print function of Python. This article explores how to implement a pretty print functionality for linked lists in Python. By presenting the nodes and their associated information in an organized and visually appealing way, developers can easily visualize the structure of the linked list, aiding in comprehension and efficient problem-solving. Discover how to enhance the clarity of your linked lists with Python's powerful features. How to pretty print Linked List in Python? Below are ... Read More

Advertisements