The post Divide two integers appeared first on FizzBuzzer.com.
]]>Solution
Obviously the naive approach to this problem would be to subtract the divisor from the dividend until the dividend becomes less than the divisor, while keeping track of how many times we subtracted.
This approach is not optimal. Imagine you would have to divide 2147483648
by 1
.
This problem can be solved based on the fact that any number can be converted to the format of the following:
So, we will increment our divisor by shifting it one position left at a time until it surpasses the divided. That is, multiply it by 2
, by 4
, by 8
, etc. We then shift it one position to the right to get the maximum divisor that still fits in our divided and subtract that from our current dividend. We repeat the process for the rest of our dividend until it becomes smaller than our original divisor.
Example, let dividend = 14 = 1110
and divisor = 1
. We start by taking our divisor and shift it one position to the left, making it divisor = 2
. It still is less than or equal to 14
. We continue by shifting it another position to the left, making it divisor = 4
, still less than 14
. We do another shift and make it divisor = 8
, which is still less than 14
. Finally, we shift it once more resulting in a divisor = 16
, which is greater than our dividend = 14
. Shifting it one position to the right will give us the largest divisor that fits into 14
, which is 8
and subtract that from our divided. We keep track of our multiplication factor and add it to our answer – three shifts to the left results in a factor of 8
. Our answer becomes 8
.
We continue with the rest of the dividend which is 14 - 8 = 6
. Our divisor is larger than 6
, so we shift it one position to the left making it divisor = 2
. We then shift it again making it divisor = 4
and finally another shift, resulting in a divisor = 8
, which is larger than 6
. Shifting it one position to the right will give us the largest divisor that fits into 6
, which is 4
and subtract that from our divided.. We keep track of our multiplication factor and add it to our answer – two shifts to the left results in a factor of 4
. Our answer becomes 12
.
We continue with the rest of the dividend which is 6 - 4 = 2
. Our divisor is larger than 2
, so we shift it one position to the left making it divisor = 2
. We then shift it again making it divisor = 4
which is larger than 2
. Shifting it one position to the right will give us the largest divisor that fits into 2
, which is 2
and subtract that from our divided. We keep track of our multiplication factor and add it to our answer – one shift to the left results in a factor of 2
. Our answer becomes 14
, which is also our final answer.
Full code
class Solution(object): def divide(self, dividend, divisor): """ :type dividend: int :type divisor: int :rtype: int """ sign = 1 if (dividend < 0 and divisor > 0) or (dividend > 0 and divisor < 0): sign = -1 dividend, divisor = abs(dividend), abs(divisor) ans = 0 while dividend >= divisor: tmp, d = 1, divisor while dividend >= d: d = d << 1 tmp = tmp << 1 d = d >> 1 tmp = tmp >> 1 dividend = dividend - d ans += tmp if sign < 0: ans = -ans return min(max(-2147483648, ans), 2147483647) def main(): solution = Solution() print(solution.divide(6, 2)) print(solution.divide(-1, 1)) print(solution.divide(-2147483648, -1)) if __name__ == "__main__": main()
The post Divide two integers appeared first on FizzBuzzer.com.
]]>The post Permutations II appeared first on FizzBuzzer.com.
]]>nums
, of distinct numbers, return all possible unique permutations.
Sample input
[1,2,1]
Sample output
[[1, 2, 1], [2, 1, 1], [1, 1, 2]]
Solution
In another post we showed how this problem can be solved iteratively.
We can use the same technique but add a check to skip adding the number n
to any subsequent positions of a list if we stumble upon a duplicate.
Let nums = [1,2,1]
. And let ans = [[]]
. The first number is 1
and the first list in ans
is []
. We then make a copy of []
and add 1
at every position in []
which results in [1]
. We add the newly created list to our new answer list and replace ans
with that and repeat. The next number is 2
. We then iterate over ans
and add 2
at every possible position in every list we iterate over in ans
. The only list in ans
is [1]
. So we make a copy and add 2
at position 0
and then make another copy and add 2
at position 1
. We add the resulting lists to our new answer list and replace ans
with that list, resulting in ans = [[2,1], [1,2]]
. The next number in nums
is 1
. Again, we then iterate over ans
([[2,1], [1,2]]
) and add 1
at every possible position in every list in ans
. So for list [2,1]
in ans
we get [1,2,1]
for position 0
and [2,1,1]
for position 1
. We then see that we just added 1
at a position where an equal was at. We immediately break and skip adding the number 1
to position 2
in the list. We continue with the list [1,2]
in ans
. We create a new list [1,1,2]
and see that at position 0
there was another number equal to 1
(duplicate) we break and our ans
will become ans = [[1,2,1], [2,1,1], [1,1,2]
.
So how come we can skip adding a number n
to any subsequent positions once we found a duplicate? That is, suppose we have a list [1,7]
and we are currently inserting the number n = 1
at position 0
. Sure we can skip inserting n
at position 1
to avoid a duplicate list [1,1,7]
but how come we can skip inserting n
at position 2
in order to get a resulting list [1,7,1]
? Well, this is because we also inserted 7
at every possible position in every list when we were iterating over 7
in a previous iteration. That is, we will already have [7,1]
(because we added 7
at position 0
and 1
for the list [1]
). And because we already have list [7,1]
we can construct our missing list, [1,7,1]
, easily when we are adding (or already have added) n = 1
at position 0
of [7,1]
. So in other words, nothing is left behind
Full code
class Solution(object): def permuteUnique(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ ans = [[]] for n in nums: new_ans = [] for perm in ans: for i in range(0, len(perm) + 1): new_ans.append(perm[:i] + [n] + perm[i:]) if i < len(perm) and perm[i] == n: break ans = new_ans return ans def main(): solution = Solution() print(solution.permuteUnique([1, 2, 1])) if __name__ == "__main__": main()
The post Permutations II appeared first on FizzBuzzer.com.
]]>The post Permutations challenge – Iterative solution appeared first on FizzBuzzer.com.
]]>nums
, of distinct numbers, return all possible permutations.
Sample input
[1,2,3]
Sample output
[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ]
Solution
In another post we showed how this problem can be solved using a recursive technique by swapping. We stumbled upon a nice iterative solution that we thought might be worth sharing.
The idea is to start at an empty list of list ans = [[]]
. We then iteratively are going to expand our ans
list. We are going to do this by iterating over every number n
in nums
and insert it at every possible position in every list that is currently in ans
.
Let nums = [1,2,3]
. And let ans = [[]]
. The first number is 1
and the first list in ans
is []
. We then make a copy of []
and add 1
at every position in []
which results in [1]
. We add the newly created list to our new answer list and replace ans
with that and repeat. The next number is 2
. We then iterate over ans
and add 2
at every possible position in every list we iterate over in ans
. The only list in ans
is [1]
. So we make a copy and add 2
at position 0
and then make another copy and add 2
at position 1
. We add the resulting lists to our new answer list and replace ans
with that list, resulting in ans = [[2,1], [1,2]]
. The next number in nums
is 3
. Again, we then iterate over ans
([[2,1], [1,2]]
) and add 3
at every possible position in every list in ans
. So for list [2,1]
in ans
we get [3,2,1], [2,3,1], [2,1,3]
and for [1,2]
we get [3,1,2], [1,3,2], [1,2,3]
which results in our new and final ans
.
Full code
class Solution(object): def permute(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ ans = [[]] for n in nums: new_ans = [] for perm in ans: for i in range(0, len(perm) + 1): new_ans.append(perm[:i] + [n] + perm[i:]) ans = new_ans return ans def main(): solution = Solution() print(solution.permute([1, 2, 3])) if __name__ == "__main__": main()
The post Permutations challenge – Iterative solution appeared first on FizzBuzzer.com.
]]>The post Permutations challenge appeared first on FizzBuzzer.com.
]]>nums
, of distinct numbers, return all possible permutations.
Sample input
[1,2,3]
Sample output
[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ]
Solution
We are using a technique called permutations by swapping.
Full code
class Solution(object): def swap(self, nums, i, j): tmp = nums[i] nums[i] = nums[j] nums[j] = tmp def solve(self, nums, i, result): if i == len(nums)-1: result.append(list(nums)) return for j in range(i, len(nums)): self.swap(nums, i, j) self.solve(nums, i+1, result) self.swap(nums, i, j) def permute(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ ans = [] self.solve(nums, 0, ans) return ans def main(): solution = Solution() print(solution.permute([1,2,3])) if __name__ == "__main__": main()
The post Permutations challenge appeared first on FizzBuzzer.com.
]]>The post Rotate Matrix / Image challenge appeared first on FizzBuzzer.com.
]]>Solution
We will work through the matrix layers. The layers of a matrix are illustrated below in different colours:
There are a total of layers. We then iterate of the length of each layer and shift our matrix cells, side for side:
for c in range(l, n-l-1): top = m[l][c] # left goes to top m[l][c] = m[n-1-c][l] # bottom goes to left m[n-1-c][l] = m[n-l-1][n-c-1] # right goes to bottom m[n-l-1][n-c-1] = m[c][n-l-1] # top goes to right m[c][n-l-1] = top
We need to temporary store the element of the top side of a layer before we replace it because we are going to need it at the end of the circle top <- left <- bottom <- right <- top
. And thats it.
The full code is listed below.
Full code
import numpy as np class Solution(object): def rotate(self, m): """ :type matrix: List[List[int]] :rtype: void Do not return anything, modify matrix in-place instead. """ n = len(m) for l in range(0,n//2): for c in range(l, n-l-1): top = m[l][c] # left goes to top m[l][c] = m[n-1-c][l] # bottom goes to left m[n-1-c][l] = m[n-l-1][n-c-1] # right goes to bottom m[n-l-1][n-c-1] = m[c][n-l-1] # top goes to right m[c][n-l-1] = top print(np.matrix(m)) def main(): solution = Solution() solution.rotate([[1]]) solution.rotate([[1,2],[3,4]]) solution.rotate([[1,2,3],[4,5,6],[7,8,9]]) solution.rotate([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]) solution.rotate([[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20],[21,22,23,24,25]]) if __name__ == "__main__": main()
The post Rotate Matrix / Image challenge appeared first on FizzBuzzer.com.
]]>The post Time series queries challenge appeared first on FizzBuzzer.com.
]]>In this challenge you are working with a time series of stock prices. You are given historical records where the stock at time had a price . You have to answer types of queries of the form :
For type , given a value , what’s the maximum price of the stock at a time greater or equal to ?
If for any of these queries the answer is not defined, i.e. there are no historical records that match the query, the answer is .
Input Format
In the first line, there are two space-separated integers and denoting the number of historical records and the number of queries, respectively.
The second line contains space-separated integers denoting the time-stamps . The next line contains space-separated integers denoting the price of stock , where value corresponds to the time-stamp.
Next, lines follow and each of them describes a single query. Each query is given as two space-separated integers. The first of them is either or and denotes the type of the query followed by a single integer denoting the value to be queried.
Constraints
Output Format
For each of the queries, print the answer on a new line. If the answer is not defined, print .
Sample Input 0
5 5 1 2 4 8 10 5 3 12 1 10 1 10 1 4 2 8 2 3 1 13
Sample Output 0
4 1 10 12 -1
Explanation 0
In the sample, there are data records and queries to answer. At time the price was , at time the price was , at time the price was , at time the price was , and finally, at time the price was .
In the first query, we are asked for the minimum time at which the price was at least . The answer is because at this time the price was and there is no earlier time with a price at least .
In the second query, we are asked for the minimum time at which the price was at least . The answer is because the price at this time was which is greater than .
In the third query, we are asked for the maximum price at time or greater. The answer is because there are two data records with time at least and the highest price among them is .
In the fourth query, we are asked for the maximum price at time or greater. The answer here is .
In the last query, we are asked for the minimum time at which the price was at least . Since there is no data record with price or greater, the answer is .
Solution
For the algorithm we will use a Binary Search Tree for query type 1 and Binary Search in range for query type 2.
So lets go ahead and implement a very simple Binary Search Tree (BST) data structure:
private static class BSTNode { public int key; public int value; public BSTNode left = null; public BSTNode right = null; public BSTNode(int key, int value) { this.key = key; this.value = value; } public BSTNode add(int key, int value) { if (key <= this.key) { if (this.left == null) { this.left = new BSTNode(key, value); return this.left; } else { return this.left.add(key, value); } } else { if (this.right == null) { this.right = new BSTNode(key, value); return this.right; } else { return this.right.add(key, value); } } } public int search(int v) { if (this.key >= v) { return this.value; } if (v > this.key) { if (this.right != null) { return this.right.search(v); } } return -1; } @Override public String toString() { StringBuilder sb = new StringBuilder("["); sb.append(this.key + "->"); if (this.left == null) { sb.append("null"); } else { sb.append(this.left.toString()); } sb.append(", "); if (this.right == null) { sb.append("null"); } else { sb.append(this.right.toString()); } sb.append("]"); return sb.toString(); } }
The BST implementation will take the price of a stock as a key and the time as value. It also has a toString()
method to pretty print our BST and a search(int v)
method to return the first value of a node that has key >= v
. This will answer any queries of type 1. We then go on to implement a helper function that constructs a BST from our given arrays t
and p
:
private static BSTNode priceTimeTree(int[] t, int[] p) { BSTNode root = new BSTNode(p[0], t[0]); for (int i = 1; i < p.length; i++) { root.add(p[i], t[i]); } return root; }
For queries of type 2 we will use a simple Binary Search with range algorithm on our time array t
. That is, we will search t
for first t[i]
with t[i] >= v
and return i
:
private static int binarySearch(int[] t, int l, int h, int v) { if (l > h) { return t.length; } else { int mid = l + (h - l) / 2; if (t[mid] >= v) { return Math.min(mid, binarySearch(t, l, mid - 1, v)); } else { // Go right return binarySearch(t, mid + 1, h, v); } } }
We also construct a precomputed array, maxPriceFromIndex
, with maxPriceFromIndex[i]
holding the maximum price starting from index i
till index n-1
:
int[] maxPriceFromIndex = new int[n]; maxPriceFromIndex[n - 1] = p[n - 1]; for (int i = n - 2; i >= 0; i--) { maxPriceFromIndex[i] = Math.max(p[i], maxPriceFromIndex[i + 1]); }
Finally, we can combine the two algorithms to get our solution to the problem:
private static int solve(int type, BSTNode priceTimeTree, int[] maxPriceFromIndex, int[] t, int[] p, int v) { if (type == 1) { return priceTimeTree.search(v); } else { // Binary search in array t for first t[i] with t[i] >= v int i = binarySearch(t, 0, t.length - 1, v); if (i < t.length) { return maxPriceFromIndex[i]; } else { return -1; } } }
The full source code to the problem is listed below. It also includes a brute force solution.
Full code
public class TimeSeriesQueries { /******************************** * BruteForce *****************************************/ private static int max(int l, int h, int[] a) { int ans = a[l]; for (int i = l; i <= h; i++) { ans = Math.max(ans, a[i]); } return ans; } private static int bruteForce(int type, int[] t, int[] p, int v) { if (type == 1) { for (int i = 0; i < p.length; i++) { if (p[i] >= v) { return t[i]; } } } else { for (int i = 0; i < t.length; i++) { if (t[i] >= v) { // Find maximum return max(i, t.length - 1, p); } } } return -1; } /**********************************************************************************/ private static class BSTNode { public int key; public int value; public BSTNode left = null; public BSTNode right = null; public BSTNode(int key, int value) { this.key = key; this.value = value; } public BSTNode add(int key, int value) { if (key <= this.key) { if (this.left == null) { this.left = new BSTNode(key, value); return this.left; } else { return this.left.add(key, value); } } else { if (this.right == null) { this.right = new BSTNode(key, value); return this.right; } else { return this.right.add(key, value); } } } public int search(int v) { if (this.key >= v) { return this.value; } if (v > this.key) { if (this.right != null) { return this.right.search(v); } } return -1; } @Override public String toString() { StringBuilder sb = new StringBuilder("["); sb.append(this.key + "->"); if (this.left == null) { sb.append("null"); } else { sb.append(this.left.toString()); } sb.append(", "); if (this.right == null) { sb.append("null"); } else { sb.append(this.right.toString()); } sb.append("]"); return sb.toString(); } } private static BSTNode priceTimeTree(int[] t, int[] p) { BSTNode root = new BSTNode(p[0], t[0]); for (int i = 1; i < p.length; i++) { root.add(p[i], t[i]); } return root; } private static int binarySearch(int[] t, int l, int h, int v) { if (l > h) { return t.length; } else { int mid = l + (h - l) / 2; if (t[mid] >= v) { return Math.min(mid, binarySearch(t, l, mid - 1, v)); } else { // Go right return binarySearch(t, mid + 1, h, v); } } } private static int solve(int type, BSTNode priceTimeTree, int[] maxPriceFromIndex, int[] t, int[] p, int v) { if (type == 1) { return priceTimeTree.search(v); } else { // Binary search in array t for first t[i] with t[i] >= v int i = binarySearch(t, 0, t.length - 1, v); if (i < t.length) { return maxPriceFromIndex[i]; } else { return -1; } } } public static void main(String[] args) throws FileNotFoundException { System.setIn(new FileInputStream(System.getProperty("user.home") + "/" + "in.txt")); Scanner in = new Scanner(System.in); int n = in.nextInt(); int q = in.nextInt(); int[] t = new int[n]; for (int t_i = 0; t_i < n; t_i++) { t[t_i] = in.nextInt(); } int[] p = new int[n]; for (int p_i = 0; p_i < n; p_i++) { p[p_i] = in.nextInt(); } BSTNode priceTimeTree = priceTimeTree(t, p); int[] maxPriceFromIndex = new int[n]; // maxPriceFromIndex[i] contains maximum price starting from index i till index n-1 maxPriceFromIndex[n - 1] = p[n - 1]; for (int i = n - 2; i >= 0; i--) { maxPriceFromIndex[i] = Math.max(p[i], maxPriceFromIndex[i + 1]); } for (int a0 = 0; a0 < q; a0++) { int type = in.nextInt(); int v = in.nextInt(); System.out.println(solve(type, priceTimeTree, maxPriceFromIndex, t, p, v)); } in.close(); } }
The post Time series queries challenge appeared first on FizzBuzzer.com.
]]>The post Longest valid parentheses challenge appeared first on FizzBuzzer.com.
]]>(
and )
, find the length of the longest valid (well-formed) parentheses substring.
Sample input
(()
Sample output
2
Sample input 1
)()())
Sample output 1
4
Solution
We will solve this problem using a Stack. We are going to iterate over the input string s
using an index i
and push index i
on the stack. While we iterate, we will check the letter positioned at the index contained on top of the stack (stack.peek()
). If s[stack.peek()]
is the letter (
and the current character is )
we will pop the top of the stack. We will keep popping as long as the later is true.
Once we iterated over all the letters in the input string the stack can either be empty or contain those indices for which we couldn’t find a counterpart parenthesis. For example, if we consider the input )()())
, the stack will contain the index 0
and 5
at the end of the iteration.
In case the stack isn’t empty we will iterate over all indices contained in the stack and keep track of the maximum distance between two adjacent indices, since this distance represents the length of a valid (well-formed) parentheses substring. We then return the maximum distance.
In case the stack is empty, we know that the entire input string is a well-formed parentheses string and return the length of that string.
Full code
class Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def push(self, item): self.items.append(item) def pop(self): return self.items.pop() def peek(self): return self.items[len(self.items)-1] def size(self): return len(self.items) def __str__(self): return ",".join([str(element) for element in self.items]) class Solution(object): def longestValidParentheses(self, s): """ :type s: str :rtype: int """ ans = 0 stack = Stack() i = 0 while i < len(s): while i < len(s) and s[i] == ')' and (not stack.isEmpty() and s[stack.peek()] == '('): stack.pop() i += 1 if i < len(s): stack.push(i) i += 1 if stack.isEmpty(): return len(s) b = len(s) while not stack.isEmpty(): a = stack.pop() ans = max(ans, b - a - 1) b = a ans = max(ans, b) return ans def main(): solution = Solution() print(solution.longestValidParentheses(")()())")) # 4 print(solution.longestValidParentheses("(()")) # 2 print(solution.longestValidParentheses("()")) # 2 print(solution.longestValidParentheses("())")) # 2 if __name__ == "__main__": main()
The post Longest valid parentheses challenge appeared first on FizzBuzzer.com.
]]>The post BMW software engineer interview experience in Munich appeared first on FizzBuzzer.com.
]]>I have studied computer science at an accredited university in Munich and have over 4 years of working experience in software development. I do lots of side projects on free time and contribute to open source projects.
I have applied several times for various software engineering roles at BMW, Munich with no luck. Usually I ended up getting a standard rejection several months later (7-8) letting me know that my application will no longer be considered.
Then one day I have received an email out of the blue telling me that they are interested in me and would invite me to an interview.
The first interview was just a phone session with HR, just to set up an onsite interview. So I went ahead and setup an onsite interview for the next day because they wanted me for the interview as soon as possible. We had scheduled an onsite interview for 17:00 so I can be there right after work.
The next day I arrived there 10-15 minutes early and waited in the lobby. At 17:05 my interviewer, in a suit, which would also be my project manager picked me up and informed me that two other guys will also join us. One being her boss and another guy who was suppose to be an engineer.
We went up to the 3rd floor and searched for a free meeting room. We sat down and waited a while. She then told me that somehow my resume ended up on her bosses desk and that they were interested in me. Funny because somehow the last time I heard from them it was an email telling me that I am no longer considered as a candidate. Meanwhile none of the other guys was showing up. I could clearly see that she was kinda embarrassed. Maybe because she also just started 6 months earlier and wasn’t used to that, I guess. She tried calling them but none of them was answering their phones.
She then suggested we proceed by letting her tell me a bit about the department, what they are doing and what they are looking for. So the short story was that apparently their department is responsible for maintaining (or even extending) the backend software that is responsible for providing the drivers with information such as weather on the little screen found in the car’s dashboard. Apparently their software doesn’t scale very well and customers are often faced with unavailable service. She told me that they are planning to move their services on to the AWS or OpenShift (but she didn’t quite knew what that is). Buzzwords like DevOps, Cloud and Agile were also mentioned pretty often.
When I finally got the chance to ask a few questions, I quickly realised that I was talking to the wrong person. I mean, she didn’t know what Git or a version control system in general was. Nor what programming languages they were using. I also found out that they are working with non-agile methods (despite agile being mentioned very often) and that they have release calendars maybe once a year or so with tons of paper work and processes in between.
Anyhow, the time was 17:21 and none of those other interviewers had shown up. She left the room in hopes that she would find them, but with no luck. So we started the interview with me introducing myself without them. After about 10 minutes two suits show up not even apologising for being late. So once I introduced myself they started asking me different questions. There was just one question of technical nature at the beginning. The guy drew a diagram that illustrated a chain of systems and I was asked “What could be the reason that the response time at this end of the chain was so slow/long? And what can you suggest in order to make it better.” I answered his question pretty well, introducing caching etc and his reply was “Yeah thats good. But one reason for the long waiting could be the fact that at this end when to many cars connect to the server and the server’s port numbers are all in use it could cause a congestion”. That was it. No other technical questions followed. Bear in mind that this was for an software engineering position. The discussion took about 5 minutes tops. Right after that, the older guy in the suit got up, said quickly goodbye and left. I wasn’t quite sure what his role was since he didn’t introduce himself, but I am guessing he was their boss.
The rest of the questions were just about me being willing to work on weekends when I have to and being willing to be on-call duty after working hours. Questions about my future goals, etc.
Meanwhile the first interviewer also left. It was just me and one of the three suits. We talked some more, mainly administrative stuff and of course salary expectations. He asked me what my salary expectation was and I replied without any hesitance 70,000EUR. This salary is pretty normal, if not even low in Munich considering I have received other offers for 120,000 and 80,000 a few months later. Nonetheless, he just laughed and told me that this was pretty high, while writing it down in his notepad. I didn’t respond. I just wanted to leave after the whole, in my opinion negative, experience. He then asked me if I wanted to work 35h or 40h during the week. I responded I don’t mind working 35h. He then again mentioned that 70k a year are way to much for 40h and for 35h there is no chance I can get 70k.
After that, we wrapped everything up with him letting me know that I will move to the next round, which would also be the final round. It will be an HR interview with questions like “What are your strengths and weaknesses?”. He told me that they will contact me and let me know about a date for the final interview.
Well, I never heart from them again, not even an email telling me that they wont proceed after all.
I wasn’t even mad because I now know, thanks to this experience, that BMW is not a company that I want to work for (at least not as a software engineer) and wouldn’t waste my time anymore applying there. I wouldn’t even suggest it to any of my friends. The main reasons are summarised:
The post BMW software engineer interview experience in Munich appeared first on FizzBuzzer.com.
]]>The post Search for a range challenge appeared first on FizzBuzzer.com.
]]>If the target is not found in the array, return .
Sample input
[5, 7, 7, 8, 8, 10] 8
Sample output
[3, 4]
Solution
class Solution(object): def search(self, nums, n, start, end, ans): if start > end: return mid = start + (end - start)//2 if n == nums[mid]: ans[0] = min(ans[0], mid) ans[1] = max(ans[1], mid) self.search(nums, n, start, mid-1, ans) self.search(nums, n, mid+1, end, ans) def searchRange(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ ans = [len(nums), -1] self.search(nums, target, 0, len(nums)-1, ans) if ans[0]==len(nums): return [-1,-1] return ans def main(): solution = Solution() print(solution.searchRange([5, 7, 7, 8, 8, 10], 8)) if __name__ == "__main__": main()
The post Search for a range challenge appeared first on FizzBuzzer.com.
]]>The post Upgrading to PHP 7 on Amazon Linux EC2 Instance appeared first on FizzBuzzer.com.
]]>Also as of July 2016, Amazon officially added PHP7 to its repository so you can install it using yum
. So first thing I did was create a backup image of my EC2 instance before I went on with the upgrade. Once I had my backups done and proceeded with the PHP 7 upgrade.
Here are the steps I took in order to upgrade from PHP 5.x to 7.
Login to your Linux instance and perform the regular system updates first
$ sudo yum update
Stop the running web server
$ sudo service httpd stop
Remove any existing PHP packages
$ sudo yum remove php*
Remove old web server installs
$ sudo yum remove httpd*
Update yum
package repository
$ sudo yum clean all $ sudo yum upgrade -y
Install Apache 2.4
$ sudo yum install httpd24
Install PHP 7 packages
$ sudo yum install php70 php70-mysqlnd php70-imap php70-pecl-memcache php70-pecl-apcu php70-gd
Install a new version of mod_ssl
$ sudo yum install mod24_ssl
I also needed to reconfigure /etc/httpd/conf/httpd.conf
and /etc/httpd/conf.d/ssl.conf
as I did in this post in order to enable SSL and pretty permalinks.
Finally all I needed to do is start my web server
$ service httpd start
The post Upgrading to PHP 7 on Amazon Linux EC2 Instance appeared first on FizzBuzzer.com.
]]>