Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 284 of 2109
Program to find out the similarity between a string and its suffixes in python
In this problem, we need to find the similarity between a string and all its suffixes. The similarity is defined as the length of the longest common prefix between the original string and each suffix. We then sum up all these similarities. For example, if the string is 'abcd', the suffixes are 'abcd', 'bcd', 'cd', 'd'. We compare each suffix with the original string to find how many characters match from the beginning. Understanding the Problem Let's see how this works with the string 'tpotp' ? Original string: 'tpotp' Suffixes and their similarities: 'tpotp' → ...
Read MoreProgram to find out the letter at a particular index in a synthesized string in python
Suppose, we are given a string input_str. We need to find all possible substrings from the given string, then concatenate all the substrings in lexicographic order into another string. Given an integer value k, our task is to return the letter at index k from the concatenated string. So, if the input is like input_str = 'pqrs', k = 6, then the output will be 'p'. Understanding the Problem The substrings from the given string 'pqrs' in lexicographic order are: p, pq, pqr, pqrs, q, qr, qrs, r, rs, s. If we concatenate these strings, it ...
Read MoreProgram to find out the sum of numbers where the correct permutation can occur in python
Given a number n, we need to find all possible permutations of positive integers up to n, sort them lexicographically, and number them from 1 to n!. When some values in a "special permutation" are forgotten (replaced with 0s), we must find all permutations that could match the original and sum their lexicographic positions. For example, if the special permutation is [0, 2, 0] with n=3, the possible original permutations are [1, 2, 3] (position 2) and [3, 2, 1] (position 5), giving us a sum of 7. Algorithm Steps The solution uses factorial number system and ...
Read MoreProgram to determine the minimum cost to build a given string in python
Suppose we have to build a string str of length n. To build the string, we can perform two operations: Add a character to the end of str for cost a Add a substring that already exists in the current string for cost r We need to calculate the minimum cost of building the string str using dynamic programming. Example If the input is a = 5, r = 4, str = 'tpoint', then the output will be 29. To build the string 'tpoint', the ...
Read MoreProgram to find maximum score by splitting binary strings into two parts in Python
Suppose we have a binary string s. We need to split it into two non-empty substrings s1 and s2. The score of this split is the count of "0"s in s1 plus the count of "1"s in s2. We have to find the maximum score we can obtain. So, if the input is like s = "011001100111", then the output will be 8, because we can split the string like "01100" + "1100111". Then, the score is 3 + 5 = 8. Algorithm To solve this, we will follow these steps − ones := number ...
Read MoreProgram to find matrix for which rows and columns holding sum of behind rows and columns in Python
Given a matrix, we need to find a new matrix where each element at position res[i, j] contains the sum of all elements from the original matrix where row r ≤ i and column c ≤ j. This is known as calculating the prefix sum matrix or cumulative sum matrix. Problem Understanding For each position (i, j) in the result matrix, we sum all elements in the rectangle from (0, 0) to (i, j) in the original matrix. If the input matrix is ? 8 2 7 4 Then ...
Read MoreProgram to find length of longest sublist containing repeated numbers by k operations in Python
Suppose we have a list called nums and a value k, now let us consider an operation by which we can update the value of any number in the list. We have to find the length of the longest sublist which contains repeated numbers after performing at most k operations. So, if the input is like nums = [8, 6, 6, 4, 3, 6, 6] k = 2, then the output will be 6, because we can change 4 and 3 to 6, to make this array [8, 6, 6, 6, 6, 6, 6], and the length of sublist ...
Read MoreProgram to find length of longest contiguous sublist with same first letter words in Python
Suppose we have a list of lowercase alphabet strings called words. We have to find the length of the longest contiguous sublist where each word has the same first letter. So, if the input is like words = ["she", "sells", "seashells", "on", "the", "sea", "shore"], then the output will be 3, because the longest contiguous sublist is ["she", "sells", "seashells"] where each word starts with 's'. Algorithm To solve this, we will follow these steps − Initialize cnt = 1 to track current sequence length Initialize maxcnt = 0 to track maximum length found Initialize ...
Read MoreProgram to find number of possible position in n-person line with few person at front and back in Python
Suppose we have three numbers n, a and b. Consider we are in a line of n people, and we are unaware about our position in the line. But we know there are at least a number of people in front of us and at most b number of people behind us. We have to find the number of possible positions for us. So, if the input is like n = 10, a = 3, b = 4, then the output will be 5. There are 10 people in the line with at least 3 people in front and ...
Read MoreProgram to find lexicographically largest mountain list in Python
A mountain list is a sequence that strictly increases to a peak and then strictly decreases. Given three positive numbers n, lower, and upper, we need to find the lexicographically largest mountain list of length n with all values in range [lower, upper]. The challenge is ensuring both increasing and decreasing parts are non-empty while maximizing the lexicographic order. Problem Analysis For a valid mountain list of length n: Must have at least one increasing element and one decreasing element Total possible unique values = upper − lower + 1 Maximum mountain length = 2 ...
Read More