Found 34469 Articles for Programming

Count Substrings with Number of 0s and 1s in Ratio of X : Y

Shubham Vora
Updated on 17-Jul-2023 12:40:18

374 Views

In this problem, we will count substrings of the given binary string containing the number of ‘0’ and ‘1’ characters in the X : Y ratio. The naïve approach finds all substrings of the given binary string, counts ‘0’ and ‘1’, and checks whether the counts are in the X : Y ratio. The efficient approach uses the prefix sum technique to solve the problem. Problem statement − We have given a binary string of length bin_len. We need to count substrings having a number of 0s and 1s in the ratio of X : Y. Sample examples Input ... Read More

Count Substrings that can be Made of Length 1 by Replacing "01" or "10" with 1 or 0

Shubham Vora
Updated on 17-Jul-2023 12:37:57

58 Views

In this problem, we will count substrings that we can make of length 1 by replacing the ‘10’ and ‘01’ substrings with ‘1’ or ‘0’ characters. When any binary string contains an equal number of ‘0’ and ‘1’, we can always make it of length 1 by performing the replacement operations. So, the problem is solved by finding the substrings with equal numbers of ‘0’ and ‘1’. Problem statement − We have given a binary string named bin_str and of length bin_len. We need to count the total number of substrings that we can make of length 1 by ... Read More

Check if two Binary Strings can be Made Equal by Doing Bitwise XOR of Adjacent

Shubham Vora
Updated on 17-Jul-2023 12:22:54

127 Views

In this problem, we will check whether we can convert string alpha2 to alpha1 by performing the XOR operation of any two adjacent characters and replacing both characters with an XOR value. We will use the logic based on the XOR value of two digits to solve the problem. If the string contains at least one ‘1’ and more than two adjacent consecutive characters, we can convert the alpha2 string to alpha1. Problem statement − We have given two binary strings of the same length. We need to check whether we can convert the alpha2 string to alpha1 by performing ... Read More

Check if given Morse Code is Valid

Shubham Vora
Updated on 17-Jul-2023 12:34:36

164 Views

In this problem, we will validate the Morse code. The Morse code method was used to transform the text in the encoded format, and it was very helpful to provide communication between two entities before the telephone was invented. There are standard codes for each alphabetical character containing the ‘.’ And ‘−‘. The code is prepared based on the transmission time, where ‘.’ Represents the short signals, and ‘−‘ represents the long signals. However, in this tutorial, we will use the standardized Morse code to decode and validate the string. Here is the table of standardized Morse code. ... Read More

Lazy import in Python

Siva Sai
Updated on 17-Jul-2023 15:04:44

3K+ Views

We're delving into Python's idea of lazy importing today. This subject can be quite rewarding if you're looking to increase your Python abilities or the performance of your application. This article includes all the information you need to understand Python's lazy import, supported by real-world examples. Introduction to Lazy Import in Python We must first understand what Python's term "import" entails. You can import additional Python modules or specific objects into your existing script using the import statement. Because of the flexibility to reuse code, Python is a very flexible and effective language. The drawback, especially when working with large ... Read More

How to sort by value in PySpark?

Tapas Kumar Ghosh
Updated on 17-Jul-2023 16:11:02

515 Views

PySpark is distributed data processing engine that will use to write the code for an API. PySpark is the collaboration of Apache Spark and Python. Spark is large-scale data processing platform that provides the capability to process petabyte scale data. In Python, we have PySpark built-in functions like orderBy(), sort(), sortBy(), createDataFrame(), collect(), and asc_nulls_last() that can be used to sort the values. Syntax The following syntax is used in the examples − createDataFrame() This is a built-in function in Python that represents another way to create the DataFrame from the PySpark module. orderBy() This is the built-in ... Read More

Check if a String can be Converted to Another by Inserting Character Same as both Neighbours

Shubham Vora
Updated on 17-Jul-2023 12:15:24

57 Views

In this problem, we will check whether we can convert the string alpha1 to alpha2 by inserting the same characters between any two same characters of the given string. We will use the run length encoding algorithm to solve the problem, which counts the frequency of the contiguous characters. Problem statement − We have given two strings named alpha1 and alpha2. We need to check whether we can convert the string alpha1 to alpha2 by performing an unlimited number of below operations. Choose any index, and the character at the current and previous index is the same, insert the ... Read More

How to Skip every Nth index of Numpy array?

Tapas Kumar Ghosh
Updated on 17-Jul-2023 16:08:35

781 Views

In Python, we have some built-in functions like array(), len(), append, and, mod() that can be use to Skip every Nth index of Numpy array. There are many ways for skipping the nth index of a NumPy array. The numpy modulus technique is one option. We can first arrange the array into chunks of evenly spaced intervals using the numpy.arange() method. Then, using the nth index, apply the np.mod() technique to the generated list intervals and compute the modulus of each element. Syntax The following syntax is used in the examples − array() This is an in-built method that ... Read More

Launch Website URL Shortcut using Python

Siva Sai
Updated on 17-Jul-2023 14:47:12

241 Views

Python is an easy-to-use and robust programming language that offers many features that go beyond basic math operations and data manipulation. Direct web interaction, including the option to launch website URL shortcuts, is one such convenient feature. This post will examine a Python-based method for achieving this. To help you understand the procedure, we'll provide you a few real-world examples. Importance of Launching Website URL Shortcut using Python The ability of Python to launch website URLs can be a huge benefit for many applications. Python can be used, for example, to automate some web-based processes, test online applications, scrape the ... Read More

Language Translator Using Google API in Python

Siva Sai
Updated on 17-Jul-2023 14:46:26

800 Views

Python is a high-level, interpreted language that is well-liked among developers because of its ease of use and adaptability. Many programmers all over the world use it as their primary language of choice. The numerous libraries and APIs it can connect with to carry out different operations are a crucial asset. In this article, we'll go over how to use Python to construct a Google API-based language translator. In order to give you a more concrete understanding of the topic, we will also provide some instances. Understanding Google Translate API Google Translate is an effective programme that converts text between ... Read More

Advertisements