Found 1862 Articles for Data Structure

JavaScript Program to Find Longest Common Prefix Using Word by Word Matching

Prabhdeep Singh
Updated on 12-Jul-2023 10:08:00

214 Views

Prefixes are the substrings that start from the zeroth index of the given string and can be of any size from 1 to the complete length of the string. We are given a set of strings and we have to find the common prefix among all of them in the JavaScript programming language. We have to implement the word-by-word matching approach in which we will match the words instead of the complete strings. Input arr = ["zefkefgh", "zefkdefij", "zeffdzy", "zefkdabacd"]; Output zef Explanation From all the given strings, we have the first three characters, the same and the remaining ... Read More

JavaScript Program to Find Minimum Insertions to Form a Palindrome

Prabhdeep Singh
Updated on 12-Jul-2023 10:51:42

118 Views

We are given a string and we have to find the minimum number of different character that we need to insert in the given string at any place so that the final string will be palindrome. A palindrome is a string that is just equal to the reverse of it. This problem is of dynamic programming, so we will first go for the recursive approach, then we will memorize it, and at the end we will see the tabulation of the memorization approach. Recursive ApproachExample const max = 1e5; // defining the upper limit // function to ... Read More

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

Prabhdeep Singh
Updated on 11-Jul-2023 18:08:03

141 Views

The characters used in an arrangement of numeric notation based on the pre-Roman Roman system are known as Roman numerals. 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 = "DCCCLXXIV" Output str = 874 Explanation DCCC is the Roman representation of 800 as D represents 500 and C represents 100 LXX is the Roman representation of ... Read More

Python Program To Write Your Own atoi()

Prabhdeep Singh
Updated on 11-Jul-2023 17:08:47

241 Views

We are given a string that may represent a number and if it is a valid number then we have to convert it into an integer using the Python programming language. atoi() function is used in C programming language and used to convert the string which is passed as the parameter to it into an integer value if the string is a valid integer otherwise it shows the undefined behavior. Sample Examples Input 1 string S = "9834" Output 9834 Explanation We are given a string that represents a number so we have just got the same output. ... Read More

C Program to Find Minimum Insertions to Form a Palindrome

Prabhdeep Singh
Updated on 11-Jul-2023 16:57:21

278 Views

A palindrome is a string that is just equal to the reverse of it. We are given a string and we have to find the minimum number of insertions of any characters required to make the given string as the palindrome. We will see the three approaches: first recursive approach, then we will memorize this solution, and last, we will implement the dynamic programming approach. Recursive ApproachExample #include // library for input and output #include // library to get the integer limits #include // library for strings // function to find the minimum of ... Read More

Java Program to Find Length of the Longest Substring Without Repeating Characters

Prabhdeep Singh
Updated on 11-Jul-2023 16:49:26

835 Views

The substrings are part of the string which contains the continuous character of the string of any length from 1 to complete string. We are given a string and we have to find the length of the largest substring from the given string that only contains the unique characters. We will see three types of methods: finding every substring, sliding windows, and two-pointers. Method 1 (Finding every Substring) In this approach, we will get every substring and then will check if there are any repeated characters present or not. Example public class Solution{ // function ... Read More

Java Program To Write Your Own atoi()

Prabhdeep Singh
Updated on 11-Jul-2023 16:37:42

414 Views

atoi() function is used in C programming language and used to convert the string which is passed as the parameter to it into an integer value if the string is a valid integer otherwise it shows the undefined behavior. We will implement the atoi() function in the Java programming language. Input string str = "123" Output 123 Explanation We are given a string that represents a number so we have just got the same output. Input string str = "897c7" Output Invalid Input Explanation The given string is not a valid integer, so we have given the ... Read More

Java Program to Find Longest Common Prefix Using Word by Word Matching

Prabhdeep Singh
Updated on 11-Jul-2023 16:31:33

319 Views

We are given a set of strings and we have to find the common prefix among all of them. Prefix is a substring for a string that contains the zero index and could be of any length from 1 to a complete string. We will implement a Java program with an explanation and a discussion of the time and space complexity. Input string arr[] = {"abcdefgh", "abcdefij", "abcdzy", "abcdabacd"}; Output abcd Explanation From all the given strings, we have the first four characters the same and the remaining characters are not same for all of them. Input string arr[] ... Read More

Convert a Binary String to Another by Flipping Prefixes a Minimum Number of Times

Prabhdeep Singh
Updated on 11-Jul-2023 16:24:09

148 Views

Prefixes are the substrings that start from the zeroth index and could be of any size from 1 to the length of the given string. We are given two binary string which means both strings contain only two different types of characters and we have to make the first string equal to the second one by flipping the prefix a minimum number of times. Also, it is given that the length of both of the given strings is equal. Input 1 string str1 = "01100" string str2 = "10101" Output 3 Explanation Only operation that we can perform ... Read More

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

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

293 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

Advertisements