Array merging and sorting complexity calculation

I have one exercise from my algorithm text book and I am not really sure about the solution. I need to explain why this solution: function array_merge_sorted(array $foo, array $bar) { $baz = array_merge($foo, $bar); $baz = array_unique($baz); ...
more »

2017-10-04 16:10 (1) Answers

Extracting k largest elements

If I have n integers, is it possible to list the k largest elements out of the n values in O(k+logn) time? The closest I've gotten is constructing a max heap and extracting the maximum k times, which takes O(klogn) time. Also thinking about using ino...
more »

2017-10-02 18:10 (3) Answers

Java: Find String with the highest value

I need to accept a string as input, split it into an array of individual words ( split on " ") and return the highest scoring word as a string. Each letter of a word scores points according to it's position in the alphabet: a = 1, b = 2, c = 3 etc. I...
more »

2017-10-02 05:10 (5) Answers

Codility PermMissingElem

My solution scored only 40% correctness on Codility. What am I doing wrong? Here is the test result (https://codility.com/demo/results/trainingU7KSSG-YNX/) Problem: A zero-indexed array A consisting of N different integers is given. The array con...
more »

2017-09-29 21:09 (2) Answers

sorting k sorted lists by their max element

If I had k sorted singly linked lists and sorted them (mergesort) by each list's largest element (last in the list), what would the big O (running time / time complexity) be? Assuming list 1 ~ k has different size: n_1 ~ n_k. I was thinking O(k * log...
more »

2017-09-27 12:09 (1) Answers

search a line in preprocessed big text file

I have a data file which contains 100,000+ lines, each line just contains two fields, key and value split by comma, and all the keys are unique. I want to query value by key from this file. Loading it to a map is out of question as that consumes too ...
more »

2017-09-26 13:09 (3) Answers

Display JavaScript Math Result

I am having trouble displaying a math function, there is nothing stated wrong in the console, so I do not know where I am going wrong. the output does not display the correct answer here... Desired outcome: enter number in each input, and javascript...
more »

2017-09-22 22:09 (4) Answers

C# dynamic algorithm

I have to think of implement a dynamic algorithm of Offer Service in C#, which is generic to configuration. For Example, sales manager promotes an offer "Buy One Get One 50% off" Offer, we have to implement this offer without deploying the system. We...
more »

2017-09-22 02:09 (0) Answers

Xor algorithm with no special characters using VBA

For a project I am developing I need to use some kind of encryption algorithm to encrypt some sensitive data, where each user has a unique hex key. Basically I have to encrypt a string and write it to a file to import to a Access database (we are n...
more »

2017-09-21 23:09 (0) Answers

Optimization of a recursive function

Optimization of a recursive function Hello everybody, I’m doing a npuzzle solver and I have a mistake… When heuristic Manhattan is off I check all ways with the default order (top, bottom, left, right). When Manhattan is on I chose the smallest...
more »

2017-09-19 09:09 (0) Answers

Haskell: Sort an almost-sorted array

I've been learning Haskell in my spare time working through LYAH. Would like to improve upon my Haskell (/ Functional programming) skills by solving some problems from the imperative world. One of the problems from EPI is to print an "almost sorted a...
more »

2017-09-18 22:09 (1) Answers

Alternately mix DATA in MS EXCEL

I have one csv file which contains 10.000 rows. The 2.000 rows have the value "EXPL_1". The 3.000 rows have the value "EXPL_2". The 2.500 rows have the value "EXPL_3". The 1.500 rows have the value "EXPL_4". The 2.000 rows have the value "EXPL_5". I...
more »

2017-09-18 13:09 (4) Answers

Time Complexity Improvement

I have been trying the coding challenges on Codility.com This is one of the questions that i tried: A non-empty zero-indexed array A consisting of N integers is given. A pair of integers (P, Q), such that 0 ≤ P < Q < N, is called a slic...
more »

2017-09-18 12:09 (1) Answers