If you work with data, you've probably had to deal with the challenge of merging multiple files into one cohesive dataset. This task can be particularly difficult if you're working with tab−separated values (TSV) files. Fortunately, the Python Pandas library provides a straightforward solution for merging TSV files by a common key. In this article, we'll learn how to merge multiple TSV files using Python Pandas. To begin with, we will first see what TSV files are and how they differ from CSV files. Next, we'll see the Pandas library and explain its capabilities for working with TSV files. And ... Read More
There are two players, X and Y, who are playing a game. X will start the first and can pick 1 stone from the set of an unlimited number of stones after that Y will start and can pick the 2 stones, then X will pick 3, and so on the game will go alternatively until the sum of the total stones picked by X is less than or equal to the given number A or the sum of total stones picked by Y is less than or equal to another given number B. If the current sum of any ... Read More
In the world of image processing, merging two or more images together is a common operation. One common use case is to merge a transparent PNG image with another image to create a composite image that contains both images. In this article, we will learn how to merge a transparent PNG image with another image using PIL. PIL is a powerful library for working with images in Python. It provides a range of functions for opening, manipulating, and saving different types of image files. The library is compatible with a wide range of image formats, including JPEG, PNG, BMP, ... Read More
Peaks are defined as the point or index in the array where are both left and right sides values are smaller than the value of that index. And Troughs are defined as the point or index of the array where are both left and right sides values are greater than the value of that index. In this problem, we have given an array 'array' of size n of integers. Our task is to minimize or reduce the count of peaks and troughs of the given array by performing an operation. Operation is that we can replace at most one value of the ... Read More
We are given two strings and we have to check if it is possible to convert the first string to another by performing any number of times a particular given task. The tasks that can be performed on the given first string only and the tasks are: Choose any index i such that i < length(A) -1 and swap ith character with the next character. We are given an integer k and we can choose any consecutive k indexes of the first string only if they are ... Read More
We are given three strings of equal size equal to 2*N, where N is an integer. We have to create a string of the size 3*N and at least two strings from the given strings be the subsequence of it. Also, the given strings are binary strings which means they only contain two different characters '0' and '1'. We will implement a code by traversing over the string and getting the frequency of the zeros and ones. Sample Examples Input string str1 = “11”; string str2 = “10”; string str3 = “10”; Output 110 ... Read More
Set bits are the bits in the binary representation of the number which are '1'. The binary representation of the number contains only two digits '1' and '0', also it may be present in the form of a string. We are given a string, the binary representation of a given number, and an integer k. We have to get all the substrings of the length k from the given string and take the bitwise OR of all of them and at last, we have to return the number of the set bits present in the final string. Sample ... Read More
In a string, a subsequence is a string that can be formed by deleting some character from it which means it contains some character from the string may be all or none and all will be present in the same order of the string. Among two strings we have to find the longest common subsequence that will not contain any repeating characters. Sample Examples Input string str1 = "aabcadjmuorrrcc" string str2 = "adbcwcadjomrorlc" Output The length of the longest common subsequence is: 8 Explanation: In the above-given strings, we have the largest ... Read More
In the English language while writing a sentence we need to start with the capital character and for any name of the city/person, etc we begin with the capital letter. Here in this problem, we are given a string and a number and we have to update the first character of all the words of the given string if their size is not less than k. Also, if the size of the words is more than k and their first character is already capitalized then we will leave it as it is. Sample Examples Input string str ... Read More
Splitting the array means we have to divide the array and make subsets. Here in this problem, we have given an array of integers with size n and integer k and our goal is to calculate the lowest cost by splitting the whole given array into the subsets of size k and adding the highest k/2 element of each subset into the cost. NOTE: here we consider a ceiling of k/2. Let’s see examples with explanations below to understand the problem in a better way. Sample Example Input n: 4 array: [ 3, 4, 2, 1 ... Read More