Found 34494 Articles for Programming

Find the final String by incrementing prefixes of given length

Shubham Vora
Updated on 31-Aug-2023 09:20:34

69 Views

In this problem, we need to increase each character of multiple prefixes of size given in the array. The naïve approach to solving the problem is to take each prefix of the size given in the array and increment each character of the prefix by 1. The best approach is to create the prefix array using the given array and update each string character in the single iteration. Problem statement − We have given a string alpha of length N. Also, we have given a prefixes array containing the positive integer. The prefixes[i] represent that take prefix of length prefixes[i] ... Read More

Count ways to select three indices from Binary String with different adjacent digits

Shubham Vora
Updated on 16-Oct-2023 17:35:07

75 Views

In this problem, we will find the number of pairs of 3 indices so that any adjacent indices don’t have the same value in the pair. We can get the output by checking each pair of 3 indexes, but it can be more time-consuming. Another approach to solving the problem is to take the current index and also take the index from left and right, which doesn’t contain a similar value to the current index's value. This way, we can count the total number of pairs each index can form and sum them to get the output. Problem statement − ... Read More

How to split the Dataset With scikit-learnís train_test_split() Function

Tushar Sharma
Updated on 28-Aug-2023 20:25:37

119 Views

Embarking on the vast domains of machine learning and data science, one encounters tasks that might appear inconsequential but hold a crucial position in the broader perspective. One such vital task is the division of data into training and validation sets - a foundational step for creating an effective predictive model. Scikit-learn, a prominent Python library for machine learning, boasts a versatile function, train_test_split(), crafted to address this task with remarkable ease. This treatise aims to steer you through the process of partitioning your data using scikit-learn's train_test_split() function. Syntax from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = ... Read More

Count even indices of String whose prefix has prime number of distinct Characters

Shubham Vora
Updated on 16-Oct-2023 16:57:47

74 Views

In this problem, we will find total invalid characters in the given string. If total distinct characters till the particular even index is prime, we can say the character is invalid. We can use the map data structure to count the total number of distinct characters while traversing the string. Also, we can use the string of characters to keep track of the distinct digits. Also, for every character, we can check whether its index is even and whether distinct characters are prime. Problem statement – We have given a string alpha containing the N characters. We need to find ... Read More

How to Split Data into Training and Testing in Python without Sklearn

Tushar Sharma
Updated on 28-Aug-2023 20:20:21

524 Views

In the domain of machine learning or artificial intelligence models, data stands as the backbone. The way this data gets handled shapes the holistic performance of the model. This includes the indispensable task of segregating the dataset into learning and verification sets. While sklearn's train_test_split() is a frequently employed method, there could be instances when a Python aficionado might not have it at their disposal or is curious to grasp how to manually attain a similar outcome. This discourse delves into how one can segregate data into learning and verification sets without leaning on sklearn. We will bank on Python's ... Read More

Check if String can be divided into two Subsequences so that product of sum is odd

Shubham Vora
Updated on 16-Oct-2023 15:25:08

76 Views

In this problem, we will check if it is possible to divide the given numeric string into two disjoint subsequences such that sum(sub1) * sum(sub2) becomes odd. We need to divide the string into two subsequences such that the sum of the digits of both becomes odd to get the odd multiplication result. Problem statement − We have given a string num_string containing the numeric characters. We need to check whether we can divide the string into two subsequences such that the multiplication of the sum of both subsequences becomes odd. Also, it is given that every character of the ... Read More

Python program to Count Uppercase, Lowercase, special character and numeric values using Regex

Gireesha Devara
Updated on 29-Aug-2023 14:05:18

453 Views

Regular expressions, commonly known as re or Regex is a powerful tool for manipulating and searching for patterns in text. In Python, regular expressions are implemented using the re-module. A regular expression is a sequence of characters that define a search pattern. The pattern is used to match and manipulate text strings, which can be very useful for tasks such as data cleaning, parsing, and validation. To count the number of uppercase letters, lowercase letters, special characters, and numeric values in a string using regular expressions (regex), we can use specific patterns to match and count the desired characters.  Following ... Read More

Odd numbers in N-th row of Pascal’s Triangle

Rinish Patidar
Updated on 28-Aug-2023 20:52:29

137 Views

The problem statement includes counting the odd numbers in N−th row of Pascal’s triangle. A pascal’s triangle is a triangular array where each row represents the binomial coefficients in the expansion of binomial expression. The Pascal’s triangle is demonstrated as below: 1 1 ... Read More

Python program to display half diamond pattern of numbers with star border

Gireesha Devara
Updated on 29-Aug-2023 14:33:02

594 Views

A half-diamond pattern is a geometric pattern that resembles the shape of a diamond, but only covers half of the diamond.  Diamond patterns can be created using loops in programming. By controlling the loops and the number of characters printed in each row, we can modify the pattern to achieve different shapes and arrangements. In this article, we will write a Python program that displays a half-diamond pattern of numbers with a star border. Input Output scenarios Let's explore some input-output scenarios for displaying the half-diamond pattern of numbers with a star border. Scenario 1 − Input: n = ... Read More

Python program to determine if the given IPv4 Address is reserved using ipaddress module

Gireesha Devara
Updated on 29-Aug-2023 14:32:00

133 Views

In the traditional IPv4 addressing scheme, IP addresses are divided into five classes: A, B, C, D, and E. Class E addresses, ranging from 240.0.0.0 to 255.255.255.255, are designated for particular purposes and are not intended for general use in the current internet infrastructure. As a result, Class E addresses are considered "reserved" and are not allocated or routable on the public internet. To determine if a given IPv4 address falls within one of the reserved IP address ranges defined by organizations like the Internet Engineering Task Force (IETF) and the Internet Assigned Numbers Authority (IANA), Python utilizes the is_reserved ... Read More

Advertisements