[Solved] Given an array, return the element that occurs the most number of consecutive times. In Java [closed]

Just compare the current element to previous one, count the number of consecutives, and if consecutive element is detected, check if it is more than existing maximum and track the value: public static int findMostConsecutive(int … arr) { int res = arr[0]; int count = 1; int maxCount = 1; for (int i = 1; … Read more

[Solved] Telephone Words problem [closed]

Based on the detailed explanation in the comment this should be a simple permutation combination problem: Each digit will have a number of characters associated to it (example 4 could mean either of G,H or I) and then for a combination of digits the permutation can be computed. 1 solved Telephone Words problem [closed]

[Solved] In a square matrix, where each cell is black or white. Design an algorithm to find the max white sub-square [closed]

First note that your solution is NOT O(n^2), it is more like O(n^4), because for each cell, you look for the largest matrix that can be of size up to O(n^2) itself, so it is totalling to O(n^4). It can be done however in O(n^2): First, define 2 auxillary functions (implemented as matrices): whitesLeft(x,y) = … Read more

[Solved] C# custom add in a List

I would use a HashSet<string> in this case: var files = new HashSet<string> { “file0”, “file1”, “file2”, “file3” }; string originalFile = “file0″; string file = originalFile; int counter = 0; while (!files.Add(file)) { file = $”{originalFile}({++counter})”; } If you have to use a list and the result should also be one, you can still … Read more

[Solved] AES. Encrypt array of bytes in powershell [closed]

I am do that i am need. New code: [Reflection.Assembly]::LoadWithPartialName(“System.Security”) $String=$buff #ARRAY OF BYTES TO ENCODE $Passphrase=”Pas” $salt=”My Voice is my P455W0RD!” $init=”Yet another key” $r = new-Object System.Security.Cryptography.AesManaged $pass = [Text.Encoding]::UTF8.GetBytes($Passphrase) $salt = [Text.Encoding]::UTF8.GetBytes($salt) $r.Key = (new-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, “SHA1″, 5).GetBytes(32) #256/8 $r.IV = (new-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15] $r.Padding=”Zeros” $c = $r.CreateEncryptor() $ms … Read more

[Solved] Replacing a range between two iterators in C++

Using std::copy(), it can be done like this: #include <iostream> #include <vector> #include <algorithm> void printVector(const std::vector<int>& v) { bool first = true; std::cout << ‘{‘; for (int i : v) { if (!first) std::cout << “, “; std::cout << i; first = false; } std::cout << “}\n”; } int main(void) { std::vector<int> v1 = … Read more

[Solved] How to create various types of inputs in order to test my algorithm? [closed]

You can use Arrays.sort() to sort your array before feeding it, each of the following describe how to achieve one thing you asked for – try to do each on the array (one at a time) before invoking sort(a) To sort the array in ascending order: Arrays.sort(a); To sort the array in descending order: Arrays.sort(a,Collections.reverseOrder()); … Read more

[Solved] Edit distance: Ignore start/end [closed]

The code to do this is simple in concept. It’s your idea of what you’d like to ignore that you can add on your own: #!perl use v5.22; use feature qw(signatures); no warnings qw(experimental::signatures); use Text::Levenshtein qw(distance); say edit( “four”, “foor” ); say edit( “four”, “noise fo or blur” ); sub edit ( $start, $target … Read more

[Solved] Draw n random integers whose sum is equal to 100 [closed]

Using only integer numbers and Fisher-Yates shuffle: program cont3; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; const SummandsCount = 5; WantedSum = 100; var i, j, t, Cnt, WhereToInsert: integer; JustNaturalNumbers: array[1..WantedSum] of Integer; DividingPoints: array[0..SummandsCount] of Integer; begin Randomize; Cnt := 1; DividingPoints[0] := 0; DividingPoints[SummandsCount] := 100; for i := 1 to WantedSum – … Read more

[Solved] How do i get the reference to the last (yet unfilled) element in a binary tree? [closed]

In the discussion below, I demonstrate using a min-heap. A max-heap works the same way, except the root is the largest node rather than the smallest, and parents are larger than their children. Things work the same way, except that you reverse the sense of the comparisons. Insertion into a binary heap follows these rules: … Read more