# 103

Sollicitatievragen voor Software Ontwikkelaar gedeeld door sollicitanten

## Meest gestelde sollicitatievragen

Sorteren: Relevantie|Populair|Datum
Er werd een Software-ontwikkelaar gevraagd...8 maart 2014

### Een vraag. Schrijf een functie hoe je twee inputstrings kan detecteren die anagrammen zijn (een woord, fase, of naam geformeerd door het herschikken van de letters van een andere, zoals bioscoop, gemaakt door ijsman). Ze zullen van je vragen om het op de

13 antwoorden

sub is_anagrams{ my ( \$s1, \$s2 ) = @_; \$s1 =~ s/\s//g; \$s2 =~ s/\s//g; return ( join( '', sort split( //, \$s1 ) ) eq join( '', sort split( //, \$s2 ) ) ? 'yes' : 'no' ); } Minder

In Java : public boolean checkAnagram(String one,String two){ if(one == null || two == null){ return false; } if(one.length() != two.length()){ return false; } one = one.toUpperCase(); two = two.toUpperCase(); List list = new ArrayList(); for(int j = 0;j &lt; one.length();j++){ list.add(String.valueOf(one.charAt(j))); } for(int i = 0;i &lt; two.length();i++){ if(!list.contains(String.valueOf(two.charAt(i)))){ return false; } } return true; } Minder

I managed to write it correctly in about 20 minutes and after two incorrect versions, which was pointed out by the interviewers. Once I did it, I was asked to explain time complexity of my solution. My solution had linear time complexity. Minder

Meer reacties weergeven

### zoek voor een reeks integers de eerste reeks waar in de som gelijk is aan de gegeven waarde en leg de moeilijkheid uit.

11 antwoorden

public static int findSubArrayThatSumsTo(int[] A, int S) { int sum = 0; int j = 0; for (int i = 0; i S) { sum-=A[j]; j++; } if (sum == S) { System.out.format("Sum (%d) found between indices %d and %d\n", S, j, i); break; } } return j; // return start-index } Minder

Complexity of above is O(n). From the look of it (given two loops), it might seem that complexity is higher. But actually every element is accessed utmost twice. So, O(2n) = O(n). Minder

The answers with keeping the running sum whilst iterating over the array, and advancing the beginning of the sequence pointer if the running sum is greater than the desired sum, only work for sequences of all positive number, right? For arrays that allow negative numbers, we need something 'smarter' like e.g. calculating the array of partial sum and finding the pair with the desired difference - O(n log n). Counter example - look for 5 in the sequence of {1, 7, -3}. The above solutions would find none, whereas the right answer is {1, 7, -3} Minder

Meer reacties weergeven

### Hoeveel 'onderdelen' zitten er op de kanten van een magic cube (3x3x3?) Wat als we dat veranderen naar 3x3x4?

6 antwoorden

The easier approach will be to think of how many cubes will be there without any face. in 3x3x3, total cubes are (3*3)*(3)=27 and only one innermost cube without a face. So its 27-1=26 cubes on all faces. Similarly, for 3x3X4, there are two innermost cubes. So its 3*3*4-2=34. Minder

Just minus the number of the pieces in the inner cube. So it is 3x3x4-1x1x2 = 34

Math question. Easy if you split it into 3 types of pieces: corners (share 3 faces and should be counted once), borders (share 2 faces) and centers. Minder

Meer reacties weergeven

### Een multiset is een set waar repetities zijn toegestaan (ex: MS1 = (1,1,2,2,2,3,3,4,4,4,4,4,5,7,7,9...) Probleem: schrijf een programma dat twee multisets ontvangt en twee intersecties teruggeeft (element 2 verschijnt drie keer op MS1 en vijf keer op MS2

6 antwoorden

Build 2 hashes to count elements on MS1 and MS2. Loop through each element on MS1 (or MS2, smaller one) checking hashes. Minder

Is it possible to use the classes (set_union, set_intersection, etc.) or they want you to implement them manually? Minder

Meer reacties weergeven

### Gegeven reeks van niet-negatieve hele getallen, terugkerend eerste unieke nummer in deze reeks (dat gebeurt slechts één keer). Voorbeeld: [1,1,2,3,56,4,7,4,3,2,56,1000] // Verwacht resultaat: 7

6 antwoorden

my \$m = [1,1,2,3,56,4,7,4,3,2,56,1000]; sub first_uniq { my ( \$arr ) = @_; my @seq = (); my \$hash = +{}; for ( @\$arr ) { push @seq, \$_ unless \$hash-&gt;{\$_}; \$hash-&gt;{\$_} += 1; } while ( my \$c = shift @seq ) { return \$c if \$hash-&gt;{\$c} == 1; } return 'nothing'; } Minder

from collections import OrderedDict l = [1,1,2,3,56,4,7,4,3,2,56,1000] counts = OrderedDict() for i in l: counts[i] = counts.get(i, 0) + 1 for key, c in counts.items(): if c == 1: print(key) break Minder

In Java: int[] arrayOne = {1,1,2,3,56,4,7,4,3,2,56,1000}; Map map = new HashMap(); for(int i=0; i Minder

Meer reacties weergeven

### In een RDBMS, een zekere tabel met de volgende kolommen: business_id, lengte- en breedtegraad De database heeft een functie genaamd afstand die positie neemt voor bedrijven en gebruikerspositie en berekent afstand. De db vraagd om uit te zoeken of bedri

5 antwoorden

Change query to something like: select business_id from positions where latitude between ?-1 and ?+1 and longitude between ?-1 and ?+1 and distance(latitude, longitude, ?, ?); Geometrically, above is shortlisting the locations within the square and applying distance formula, nearly a circle. This way indexes on latitude and longitude columns can be used. Minder

I can answer this. Imagine a 2-D (cartesian) plane. If there is a point (x,y) and you are interested to know the points within 1 unit distance, you would draw a circle of 1 unit radius around (x,y) and see which points lie within. That is what distance formula is doing. Now if you draw a square of 2 unit size such that (x,y) is it's center, (1) the square would fully enclose the circle we spoke of above (2) vertices of the square would be (x-1,y-1), (x+1, y-1), (x-1, y+1), (x+1, y+1) So the additional conditions in the WHERE clause would "shortlist" the points within the square and then the distance function would get the points within the circle. Simple! :-) Minder

@Bafniz The question is *not* related to math/geography. You must understand the problem is to optimize a query whose bottleneck is that it'll have to do a FULL TABLE SCAN! Math calculations like cos or sin or anything takes nearly a one millionth the time of doing a FULL TABLE SCAN Minder

Meer reacties weergeven

### Hoe verwijder je herhaalde waarden uit een Int Array en geef je de resulterende array terug in dezelfde volgorde als het origineel?

5 antwoorden

Solution with test: Integer[] input = new Integer[] {3, 3, 2, 1, 2, 45, 32, 1, 23, 4}; // some array to test Set uniques = new LinkedHashSet(); for(int i=0; i Minder

I think they want you to write down the algorithm and not use the languages resources, so, I write a modification of counting sort, it is O(n): def remove_dup(array): max = 0 for i in array: if i &gt; max: max = i counting = [] for i in xrange(max): counting.append(0) output = [] for i in array: c = counting[i-1] if c == 0: output.append(i) counting[i-1] += 1 return output Minder

sub unique_in_same_order { my \$a = shift; my %uniq; return grep { ++\$uniq{\$_} == 1 } @\$a; } Minder

Meer reacties weergeven

### Ik kreeg een lijst van n integers, vind de top van k integers. Wat is tijd-complexiteit van jouw oplossing? Given a list of n integers, find top k integers. What is time-complexity of your solution?

4 antwoorden

This is the sort of company where they like you provide more than one answer and also to think both like an Engineer and a Computer Scientist. So your first answer could be If I have to do it in a hurry, sort the list using the built-in sort of the language and take the top of the list. this is O(n log(n)) If it is worth it to do it right, use a heap, that you may also know as a priority queue and you have better performance. Minder

Heap insertion is O(n*log n), how can you get better performance?? That said, "Interview Candidate"'s solution does not match the claimed complexity. I think this can be done with a quick selection algorithm, which provides an average linear solution. Minder

Enoch, It's a heap of size 'k' and we're inserting 'n' elements. The Java implementation of PrioritityQueue.add does it in O(n*log(k)) complexity. Related: http://stackoverflow.com/questions/14310164/complexity-of-priorityqueue-addall Minder

Meer reacties weergeven

### Schrijf het Fibonacci-algoritme op.

3 antwoorden

In Perl use strict; use bigint; my (\$a, \$b) = (0, 1); for (1..12) { print "\$a\n"; (\$a, \$b) = (\$b, \$a+\$b); } Minder

Here is a function: (uses iteration. Not recursion) long fibo(int n) { if(n&lt;=0) { cerr&lt;&lt;"Invalid input"; return -1; } else { long a=0, b=1, c; for(int i=1; i Minder

Solution in Java: Using recursion: for(int i=1; i&lt;=number; i++){ System.out.print(fibonaci(i) +" "); } public static int fibonaci(int num){ if(num==1 || num ==2){ return 1; } return fibonaci(num-1)+fibonaci(num-2); } Using for loop: int fibCount = 10; int[] fib = new int[fibCount]; fib = 1; fib = 1; for(int i=2; i &lt; fibCount; i++){ fib[i] = fib[i-1] + fib[i-2]; } for(int i=0; i&lt; febCount; i++){ System.out.print(feb[i] + " "); } Minder

2 antwoorden