jueves, 4 de enero de 2018

Problem #2

Hello Internet Geeks!

Today it was a String day so, here it is today's problem:


Implement StrStr

Implement StrStr
From: InterviewBit
- Another question which belongs to the category of questions which are intentionally stated vaguely.
- The expectation is that you will ask for correct clarification or you will state your assumptions before you start coding. 
*Specifications are at the end of the entry. First, formulate your questions.
Ideas
* Assuming that A is length of haystack and  B of needle, time complexity expected is  O(N*M)
*If we are going to search in A, the first letter we need to find is B(0).  


Solution:

https://github.com/AlexFaru/GoodCoding-/tree/master/String



Specifications :

Implement strStr().
strstr - locate a substring ( needle ) in a string ( haystack ).
Try not to use standard library string functions for this question.
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
NOTE:
Good clarification questions:
  1. What should be the return value if the needle is empty?
  2. What if both haystack and needle are empty?
For the purpose of this problem, assume that the return value should be -1 in both cases.

jueves, 28 de diciembre de 2017

Hello Internet Geeks!

Today I´m going to share my first problem, its very cool problem and here it comes:

Nearest Smaller Element 

From: InterviewBit

Given an array, find the nearest smaller element G[i] for every element A[i] in the array such that the element has an index smaller than i.
More formally,

G[i] for an element A[i] = an element A[j] such that 
    j is maximum possible AND 
    j < i AND
    A[j] < A[i]

Elements for which no smaller element exist, consider next smaller element as -1.

Example:
Input : A : [4, 5, 2, 10, 8]
Return : [-1, 4, -1, 2, 2]

Example 2:
Input : A : [3, 2, 1]
Return : [-1, -1, -1]



Ideas:

-If we look at the value A[i-1] all the elements with i smaller and greater tan A[i-1] are not gonna work for G[i] so they are usless.

-Use the stack to put the lower values that can work with the G[i] , G[i+1]...


Solution:

Here I have the code for this problem in gitHub: https://github.com/AlexFaru/GoodCoding-/blob/master/Stacks%20&Queues/Nearest%20Smaller%20Element.txt



sábado, 23 de diciembre de 2017


Hello Internet!

My name is Alex Farías, I’m studying computer science degree at ITCG, México. I love Math and programming and those are my favorite hobbies. I’m going to be working in this space with programming topics, basically focus on data structure and algorithms. I’m sharing this like part of my portfolio for Microsoft internship interview.

 So I´m going to be sharing theory and about 5 programming problems weekly:

*Problem description

*Ideas to solve the problem

*Code
I also want to thank Salvador Orozco V. for motivating me to start with this proyect.
Join me on my one year trip!