Friday, December 1, 2017

What interviewer is looking for? Integrity Intelligence Energy

I have been following successful businessmen to learn from their success hoping to become successful and rich by changing the way I think/see everything.
Well, I believed in Warren Buffett when he said "Look for Integrity, Intelligence, and Energy"

So What interviewer is Interviewer is looking for?!

I got promoted as an expert software engineer, and started to get involved in interviews to select future promising candidates who could fit in out innovative culture.

I started to read around and learn the process. I started to focus on these 3 principles 
Integrity.
Intelligence.
Energy

It's very tricky to discover these basic values through the interview process. Here's my 5 steps to find out 
1.    Break the Ice. Make candidates proud of themselves, their biggest achievements. Once candidate is comfortable, he/she will show their best.
2.    Discover candidate attitude when facing a big challenge
3.    Discover candidate relationship /challengeswith his team
4.    Is he leaving his company in a better shape than the time he joined? Did he really make a difference?
5.    Are you smart? Expect a different answer from yours. You know the solution in hand, and you know it’s the optimal, but it’s not the only solution

Usually I handle the technical part of the interview. I get really excited when I see fresh out of college trying to provide an answer of something he never heard of. It does show some energy. Energy of trying and taking some risks.

Technical interviews has 2 types either specific to a technology, or a computer science fundamentals interview.
The specific technology or stack interviews is very easy to judge and decide if candidate is qualified or not.
Computer science interviews are so much fun, very tricky, and show candidate personality. It’s easy to find out if candidate has energy, integrity, and intelligence.

Here’s how I do it
1.    Ask a very simple famous interview question? Ask if they have seen it before?
Example: string rotation
2.    Ask an intermediate question. Listen carefully to candidate’s train of thought.
Example: Matrix rotation, check if rubix cube is completed, etc
3.    Ask a hard question? Check when would they give up.
Build

Summary
It’s so much fun to work with people who are smarter than you. This keeps me excited, ready for everyday challenges, and increase my value.

Always look for Integrity, intelligence, and Integrity.

Monday, July 17, 2017

Queue Reconstruction by Height
Come across this interesting coding example and thought of sharing my experience with this simple solution. 
Basically you have a rectangle array of 2 columns h represents person height and n represents number of tall people who have a height greater than or equal to h.. We need to reconstruct the queue.
Example
Input:
[[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]

Output:
[[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]

My simple solution would be as follow
1. convert array to list of objects (Person class)
2. sort the list by number of tall ahead then by height in ascending order.
3. Go through the list to check/change objects to the correct position of the list.
4. convert the list back to an array


Wednesday, December 16, 2015

Hw To Match Stock Holdings with any Stock Model Using SQL Full Outer Join

Problem
Here's a nice SQL challenge that I have done recently.
There are 2 friends Jack and Julie.
Jack has a list of holdings that represents stock name and amount he owns.
Julie has a Model that represents stock name and percentage she owns of the stock.
for the holding table, the Total amount is $1000.
For the Model table, the Total percentage is 100%


We would like to map Jack's holdings to Julie's Model.
We have a table of orders represented by stock name, amount, and operation type.
We are looking for a list of stocks that we need to buy or sell in order to match holdings with any given model.
Here's an example.

Solution
Using full outer Join we can provide a simple, and easy to understand solution.  We use left or right outer join most of the time, and It's very rare to use Full outer join. 
Full outer join provides you with all records from both tables a long with the matching records of each other. It's like a union of Left join and right join.


Simply Left join and Union concepts are all what we need to resolve this problem in a single SQL query.



Friday, March 27, 2015

Filter dates in a date range

Problem
We need to come with a list of dates where our service is online. Considering another list of date range(From through dates) where our service is down for maintenance.
We are looking for a date range of days, months, and may be years. So we might get a huge list of dates.
The 3 blocks on the image below represents down time of a service.
Solution
There are multiple ways to approach this problem but I need a smart way to implement it in O(1) or O(n) in the worst case.
Since I'm using C#. I can use a dictionary of datetime as a key and bool as It's value.
The dictionary keys will be all available dates with default value of true(service is available).
Since It's a dictionary, the insert operation is O(1).
Then we will go through each down time period and update the value of the Date key to true if the date is a key in our dictionary. 
Then we will return a list of Keys where the value is false.

Results
List of dates where our service is online and functioning.



Thursday, October 16, 2014

Bulding Startup knowledge

Recently, I become very interested in Startup companies and Entrepreneurship.
Becoming a successful Entrepreneur is my life Mission.
I HAVE got MY Entrepreneur Magazine’s membership to be in touch with startups news. Listening to Podcasts, reading books about it. References 

Books
Podcast
·         ssHear Startups By Alex Blumberg. Is my most favorite podcast
 Blogs 

Thursday, March 20, 2014

Combining Predicates in c#

Today, I was looking for a way to combine 2 or more predicates, We have found an MSDN post about it HERE. It explains 3 different ways to combine predicates using LINQ expressions. .

But, Can we make it simple and cool?
I guess it's time to use our creativity skills.
Think about it we just need to merge lambda expressions. In order to merge lambda expressions we always use &&/!!, so Can we do the same here?
Here's our solution below:
static void Main(string[] args)
{
    Func<Car, bool> theCarIsRed = c => c.Color == "Red";
    Func<Car, bool> theCarIsCheap = c => c.Price < 10.0;
    Func<Car, bool> theCarIsLuxury = c => c.Model == "Audi";
    Func<Car, bool> theCarIsRedOrCheap =    c =>     theCarIsRed(c)
                                                                             && theCarIsCheap(c)
                                                                             || theCarIsLuxury(c);
    List<Car> cars = new List<Car>();
    cars.Add(new Car { Color = "Red", Price = 7 });
    cars.Add(new Car { Color = "Yellow", Price = 90, Model= "Audi" });
    cars.Add(new Car { Color = "Red", Price = 11, Model = "Toyota" });
    cars.Add(new Car { Color = "Red", Price = 60, Model = "Audi" });
    Console.WriteLine("available options: " + cars.Where(theCarIsRedOrCheap).Count());
    Console.ReadLine();
}
class Car
{
    public string Color { get; set; }
    public long Price { get; set; }
    public string Model { get; set; }
}

Conclusion
Combining predicates means combining lambda expressions.  

Tuesday, March 18, 2014

MVVM and WPF Common Problems for Beginners

    For the past 3 years, I have been using Windows Presentation Foundation(WPF) and Model View ViewModel(MVVM). At the beginning I preferred having everything in code behind because It's simple, you feel more productive and finish the screen in less time. But it doesn't follow the open/close principal. The code becomes very complex when fix defects, add or change user requirements, difficult to test, business logic and controls manipulation are mixed up. Having everything in the code behind is decreasing my productivity in the long term.
   
If you are beginner in WPF and MVVM, don't expect it will be smooth trip. you will struggle at the beginning, you will have a bad moments where you are trying to investigate the binding problems. Be patient and believe that you can make it. This means you have decided to suffer now, and be more productive later.

Here's some MVVM guidelines  

  1. Reduce or eliminate your code-behind(Doesn't mean code behind breaks MVVM )
  2. Bind all of your UI inputs/outputs to your ViewModel
  3. Implement INotifyPropertyChanged on your ViewModel
  4. Put your view behavior into the ViewModel
  5. Do not put any view state into the model
  6. When testing, treat ViewModel as the Real UI
  7. Avoid events.  Use commands instead

Here's a list of some problems and a simple way to get over it

Case 1: Passing information to a user control that has It's own View model.
Solution: Instead of creating a dependency property at the user control code-behind and bound it at the parent window XAML, you can simply bound the DataContext property of the user control to the parent window view model property.

Case 2: Communication between different View models
Solution: Based on the complexity of your view models. If it's compels you can use the messenger/mediator pattern. If you can merge them into a single view model and bound and use it instead, this will save you a very big headache.

Case: Having a reference to the UI control at the view model and set the focus if needed.
Solution:

  1. You can learn about the attached behavior and create your own behavior class in order to set the focus on any control.
  2.  If your case is simple, and you would like to set the focus on a  specific control, pass the control itself as a command parameter to the view mode using. Make sure to use the Dispatcher begin invoke method if you would like to change any control properties at the model view level. this will put your code at the ui thread queue. 

To Be Continue.

Conclusion
Using MVVM and WPF is one of the bnest ways to separate your business logic and user controls manipulation. You have a hard time to get through it at the beginning. Once you are comfortable with it, you will love it and feel like converting all of your old code-behind code to the view model.