Found 1860 Articles for Data Structure

Python Program for Converting Roman Numerals to Decimal Lying Between 1 to 3999

Prabhdeep Singh
Updated on 11-Jul-2023 21:34:23

712 Views

Roman numerals are known as the characters used in an arrangement of number notation based on the pre-Roman Roman system. All major symbols are covered in the section below. In this problem, we are given a string of Roman numerals and our task is to convert Roman numerals to decimals in the range of 1 to 3999 Here are some examples and explanations to help you better understand the problem. Input str = “MXCIX” Output 1099 Explanation M is the Roman representation of 1000, XC is the Roman representation of 90, IX is the Roman representation of 9. Input str ... Read More

Largest Roman Numeral Possible by Rearranging Characters of a Given String

Prabhdeep Singh
Updated on 11-Jul-2023 16:07:53

197 Views

The characters represent Roman numbers: 'I', 'V', 'X', 'L', 'C', 'D', and 'M'. We will be given a string that may contain another character also (all the characters will be uppercase English alphabets) and we have to find the largest Roman numerical number possible by altering the position of the characters of the given string, also if it is not possible to get one, then we will return invalid as the answer. Input 1 string str = “VICML” Output MCLVI Explanation In the given string we have M have the greater value followed by the C, and then all ... Read More

Karatsuba Algorithm for Fast Multiplication of Large Decimal Numbers Represented as Strings

Prabhdeep Singh
Updated on 11-Jul-2023 21:20:07

521 Views

We are not able to store the large decimal numbers in normal data types such as the int or even in long long, so we store them in the string. When we multiply two integers represented in the form of a string it takes a lot of time more specifically N*M where N is the size of the given string. In this article, we will implement Karatsuba Algorithm for the fast Multiplication of large decimal numbers represented as strings. Input string num1 = "34984" string num2 = "937488" Output 32797080192 Explanation We will see the algorithm for the ... Read More

Python3 Program to Minimize Characters to be Changed to Make the Left and Right Rotation of a String the Same

Prabhdeep Singh
Updated on 11-Jul-2023 15:05:05

125 Views

Rotation means we have to shift each character either in a forward direction or backward direction. Forward direction means right rotation (Or anticlockwise) and backward direction means left rotation (Or clockwise). In this problem, we have given a string of size n. Our task is to find the minimum number of the character to be changed to check whether it is possible to the make left rotation and right rotation of a string the same. Let's see examples with explanations below to understand the problem in a better way. Input 1 str = "wxyz" Output 1 2 Explanation The ... Read More

PHP Program to Check if all rows of a matrix are circular rotations of each other

Prabhdeep Singh
Updated on 11-Jul-2023 14:50:21

141 Views

A rectangular array called a matrix is made up of rows and columns. And circular rotations entail rotating the array's elements so that after one rotation, the last member is in the first position and the other elements are shifted to the right. We are given an N*N matrix in this problem, and our objective is to determine whether all of the rows are circular rotations of one another. If they are, print "YES, " otherwise print "NO." In order to better understand the issue, let's look at some cases with explanations below. Input 1 mat = [ [ 7, ... Read More

Java Program to Check if all Rows of a Matrix are Circular Rotations of Each Other

Prabhdeep Singh
Updated on 11-Jul-2023 14:14:22

211 Views

Matrix consists of rows and columns to form a rectangular array. And circular rotations mean rotating the array's elements so that one rotation places the last element in the first position and the rest of the elements to the right. In this problem, we have given a matrix of n * n, and our task is to check if all rows of a matrix are circular rotations of each other then print “YES” otherwise print “NO”. Let's see examples with explanations below to understand the problem in a better way. Input 1 mat = [ [ 1, 5, 6], ... Read More

Java Program for Converting Roman Numerals to Decimal Lying Between 1 to 3999

Prabhdeep Singh
Updated on 11-Jul-2023 14:05:25

656 Views

The characters used in an arrangement of number notation based on the pre-Roman Roman system is called Roman numerals. The letters M, D, C, L, X, V, and I stand for 1000, 500, 1000, 50, 10, 5, and 1, respectively, and will discuss all main symbols in the below section. In this problem, we are given a string of Roman numerals and our task is to convert Roman numerals to decimals in the range of 1 to 3999. Let’s see examples with explanations below to understand the problem in a better way. Input 1 str = "MCMIX" Output 1 1909 ... Read More

JavaScript Program To Write Your Own atoi()

Prabhdeep Singh
Updated on 11-Jul-2023 11:42:17

231 Views

In C programming language we have a function that takes a single string or character array as the parameter and returns an integer that may be represented by the given string, if the current string is invalid then it reads only up to the first valid index and will return that value. We will see the complete code with the explanation. Sample Examples Input 1 string S = "-9845" Output 1 -9845 Explanation We are given a string that represents a number so we have just got the same output. Input 2: string str = "90 uy78" Output 2 ... Read More

Java Program for Left Rotation and Right Rotation of a String

Prabhdeep Singh
Updated on 11-Jul-2023 08:55:14

3K+ Views

Rotation means we have to shift each character either in a forward direction or backward direction. Forward direction means right rotation (Or anticlockwise) and backward direction means left rotation (Or clockwise). In this problem, we have given a string of characters of size n and integer d. Here d is less than n. Our task is to print the left rotated string or right rotated string by d integer. Only the permutation of the current string changes, not the length or frequency of the characters in the given string. Input 1 str = “apple”, d = 2 Output 1 Left ... Read More

Sort a string without altering the position of vowels

Prabhdeep Singh
Updated on 11-Jul-2023 09:02:29

574 Views

Sorting a string means we have to arrange a given string either in an ascending or descending order or any given order. In this problem given a string 'str' of size n. Our aim is to sort the given string without altering means without changing the position of vowels present in the string. Let's see examples with explanations below to understand the problem in a better way. Sample Examples Input 1 str = “abdecokfee” Output 1 abcedofkee Explanation Constant present in the string = bdckf Sort the constant string = bcdfk Merge the given string with the sorted instant string ... Read More

Advertisements