Stats: 3,191,842 members, 7,945,703 topics. Date: Wednesday, 11 September 2024 at 01:23 AM |
Nairaland Forum / Science/Technology / Programming / Programming Interview Test (3743 Views)
Programming Interview Question: Invert A Binary Tree (2) (3) (4)
Re: Programming Interview Test by Nobody: 12:04pm On May 17, 2016 |
febup here is my solution. i implemented the function solution(...) to return an int array of p's. plz check it out!
|
Re: Programming Interview Test by Nobody: 3:37pm On May 17, 2016 |
@Crotonite Very nice of you for doing this test. What you can do now is to add a timer at the start and end of your code to see how long it will take to return all the equilibrium indices of P if N = 100,000. Then rewrite your code to make it run faster using Big 0 Notation if needed. |
Re: Programming Interview Test by Nobody: 4:55pm On May 17, 2016 |
check this one out, it is quite fast (50 iterations of N = 100000 takes under 3secs i.e including the overhead of printing to stdout).
|
Re: Programming Interview Test by Nobody: 5:31pm On May 17, 2016 |
@Crotonite Please try your code on their page at this link: https://codility.com/demo/take-sample-test I don't think I can grade your code as the test belongs to the website owner at the above link. |
Re: Programming Interview Test by Nobody: 5:58pm On May 17, 2016 |
k ![]() |
Re: Programming Interview Test by Nobody: 2:47pm On May 24, 2016 |
crotonite: I went through your code, what I found was that you have prefixed the values of the array N as: int[] ar = {-1, 3, -4, 5, 1, -6, 2, 1} which was just an example they used in the test. You were meant to generate random integers within the range [−2,147,483,648..2,147,483,647]. You also have this loop: for (int j = 0; j < 50; j++) in which you are calling this function int[] result = solution(arr2, arr2.Length); This means your code is not doing what is required. 1 Like |
Re: Programming Interview Test by Nobody: 2:58pm On May 24, 2016 |
@febup
i am still newbie you know. ![]() |
Re: Programming Interview Test by Nobody: 2:59pm On May 24, 2016 |
@crotonite Nice try bro keep it up 1 Like |
Re: Programming Interview Test by jacob05(m): 3:51pm On May 24, 2016 |
larisoft:Can someone explain how this runs in O(n) cc Febup |
Re: Programming Interview Test by Nobody: 8:43pm On May 24, 2016 |
jacob05: @larisoft You need to come and explain your code, I have converted it to C# below, when I run it, it does nothing. using System; namespace larisoftBigO { class Program { static void Main(string[] args) { int[] array = new int[8]; solution2(array, ![]() } public static int solution2(int[] nums, int n) { int sum = Sum(nums); int i = 0; int left_sum = 0; while (i < nums.Length) { int right_sum = sum - left_sum - nums[i]; if (right_sum == left_sum) { Console.WriteLine(i.ToString()); Console.Read(); return i; } left_sum += nums[i]; i++; Console.Read(); } Console.Read(); return -1; } private static int Sum(int[] arr) { int a = 0; foreach(int i in arr) { a += i; } return a; } } } |
Re: Programming Interview Test by Nobody: 7:18am On May 25, 2016 |
@Crotonite Your code is the closest to the solution, you have now dethroned larisoft unless he can come up with a better solution than yours. |
Re: Programming Interview Test by Nobody: 9:12am On May 25, 2016 |
^^^ah, i don't like what i am hearing at all. Larisoft, oya dethrone crotonite back, who the heck does he think he is? He should be thankful that i have retired from programming to hunting for monitor lizards (so that i can make frontpage) |
Re: Programming Interview Test by Nobody: 9:30am On May 25, 2016 |
dhtml18: boss, make i sit for ur right hand o jare! |
Re: Programming Interview Test by Nobody: 9:36am On May 25, 2016 |
the prototype of my recent solution: import java.util.*; |
Re: Programming Interview Test by Nobody: 10:06am On May 25, 2016 |
Chai, is that language above JAVA? before me i no fit read am, it is too concentrated for me. Abi na objective Java Language? |
Re: Programming Interview Test by Nobody: 10:09am On May 25, 2016 |
codility verified my algorithm....
|
Re: Programming Interview Test by Nobody: 10:16am On May 25, 2016 |
Santa maria! i don see new one again o!! Wia is larisoft make him come debug this your codibility nonsense because adonbilivit!!! |
Re: Programming Interview Test by Nobody: 10:27am On May 25, 2016 |
dhtml18: ![]() it is java ooo... |
Re: Programming Interview Test by Nobody: 10:53am On May 25, 2016 |
Hmn, this your JAVA is so concentrated that e no be like that JAVA wey i sabi again. |
Re: Programming Interview Test by Nobody: 10:56am On May 25, 2016 |
crotonite: Now let me verify it too from my end. |
Re: Programming Interview Test by Nobody: 11:15am On May 25, 2016 |
Febup: ![]() i did not test for cases like: array == null, array.lenght >100000 || <= 0, etc. i will hv to enhance my algorithm when chanced. thanks... |
Re: Programming Interview Test by Nobody: 11:16am On May 25, 2016 |
dhtml18:code obfuscation at work sire. |
Re: Programming Interview Test by Nobody: 11:31am On May 25, 2016 |
^^^Interesting. . . |
Re: Programming Interview Test by jacob05(m): 11:46am On May 25, 2016 |
crotonite: Is the function solution not running at O(2n) ![]() |
Re: Programming Interview Test by jacob05(m): 11:51am On May 25, 2016 |
I guess they grow "linearly" the same way.. so the solution might be valid. |
Re: Programming Interview Test by Nobody: 11:55am On May 25, 2016 |
I agree with the poster above me. . . . |
Re: Programming Interview Test by Nobody: 12:00pm On May 25, 2016 |
jacob05: It is Linear 0(N) |
Re: Programming Interview Test by jacob05(m): 11:46pm On May 25, 2016 |
crotonite: In Python
|
Re: Programming Interview Test by Nobody: 9:55am On May 26, 2016 |
^^^ I don't have PHP setup on my machine so I tried your code on their site but it gave the error message below: PHP Parse error: syntax error, unexpected '=' in func.php on line 6 Parse error: syntax error, unexpected '=' in func.php on line 6 RUNTIME ERROR (tested program terminated unexpectedly) Detected some errors. /* Your code*/ function solution($A) { // write your code in PHP5.5 lSum = 0; ret = []; rSum = sum(A) ) if (rSum - A[0] == 0 ) : ret.append(1 ) lSum = A[0] for p in xrange(1, len( A ) ) : if (lSum == (rSum - (A[p] + lSum)) ) : ret.append(p) lSum += A[p] return ret } |
Re: Programming Interview Test by jacob05(m): 9:57am On May 26, 2016 |
jacob05: Febup: Attention to details ... It's in Python 2 |
Re: Programming Interview Test by Nobody: 10:12am On May 26, 2016 |
jacob05: Edited Ok I will use use .. Repl.it - Python 2 as you have suggested |
Re: Programming Interview Test by jacob05(m): 10:16am On May 26, 2016 |
Febup: use .. Repl.it - Python 2 |
Naija Coder: Test Your Coding Skills Now / Why Do Programmers Still Look For Job? / I Need Help With A Php Program
Viewing this topic: 1 guest(s)
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 38 |