Implement a prototype for a text editor application with the following functionalities:
Command
Actions:
- ["Insert", s]: Insert the string s at the current cursor position. The cursor moves right by the length of s.
- ["Left", x]: Move the cursor x positions to the left, but not past the start of the string.
- ["Right", x]: Move the cursor x positions to the right, but not past the
Asked in: MICROSOFT
Given a string, determine how many different substrings exist that have no repeating characters. Two substrings are considered different if they have different start or end indices.
Example
s = "abac"
The substrings with no repeating characters are "a", "b", "a", "c", "ab", "ba", "ac", and "bac".
Note that "aba" and "abac" do not qualify because the character 'a' is repeated in them.
Asked in: MICROSOFT
A coding competition organized to recruit software developers includes a problem involving the bitwise-OR operation. The score of a sequence is defined as the result of the bitwise-OR operation on its elements. Given an array arr of length n, identify all possible distinct scores that can be obtained by selecting any strictly increasing subsequence from the array. Return the results sorted in asce
Asked in: MICROSOFT
A foundry in Hackerland makes an alloy out of n different metals. In the manufacturing of an alloy, the composition of each metal is fixed, where the required quantity of the i-th metal in preparing 1 unit of the alloy is denoted by composition[i]. The company already has stock[i] units of metal i in their stock. The company has a budget to purchase any of the metals if needed. The cost of the i-t
Asked in: MICROSOFT
An array of integers is almost sorted if at most one element can be deleted from it to make it perfectly sorted, ascending. For example, arrays [2, 1, 7], [13], [9, 2], and [1, 5, 6] are almost sorted because they have 0 or 1 elements out of place. The arrays [4, 2, 1] and [1, 2, 6, 4, 3] are not because they have more than one element out of place. Given an array of n unique integers, determine t
Asked in: MICROSOFT
The binary cardinality of a number is the count of 1's in its binary representation. For example, the decimal number 10 corresponds to the binary number 1010, which has a binary cardinality of 2 because it contains two 1's. Given an array of decimal integers, sort it by: 1. Increasing binary cardinality (primary criterion) 2. Increasing decimal value (secondary criterion, when cardinalities are eq
Asked in: MICROSOFT
Coding Wars
There are 'N' coders standing in a line, where i denotes the ith position of a coder with a rating of Ri. All ratings are distinct.
You have to form a team of 3 from amongst them with the condition:
Any three coders with positions (i, j, k) and ratings ("Ri< Rj< Rk" or "Ri > Rj > Rk") and(1 <= i < j < k <= N)
You have to find out how many such teams exist (1 coder can be part of m
Asked in: AMAZON MICROSOFT
String Encoding
Encode a given string by collapsing consecutive instances of a single character into two pieces of information: the number of instances and the character. Note that even single characters should be run-length encoded. If the string is empty, return an empty string. Your implementation should work on all alphanumeric characters.
Function Description
Complete the function collapse
Asked in: AMAZON MICROSOFT
Break a Palindrome
A palindrome reads the same forwards and backwards, like "mom". Modify a palindrome by changing exactly one character to another character within the ASCII range [a-z].
The goal is to ensure the new string fulfills the following criteria:
1.It is not a palindrome.
2.It is alphabetically lower than the original palindrome.
3.It is the smallest possible string alphabetically
Asked in: AMAZON MICROSOFT
Vaccination Drive
In order to curb the spread of the novel COVID-19 virus, the citizens of Hackerland need to be vaccinated on priority. There are center_nodes vaccination centers in Hackerland, where each center has a status denoted by status[i]:
• Centers with a shortage of vaccines have status 1.
• Those with sufficient vaccines have status 2.
• Those with a surplus have status 3.
Vac
Asked in: AMAZON MICROSOFT JUSPAY