Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7c1784e
Added V1 algorthm, renamed the previous to V0
mariotti Nov 11, 2016
12ad7a0
example of algo description file
mariotti Nov 18, 2016
80910fc
TEST THIS IS NOT WORKING. The commit also introduces timing which has…
mariotti Nov 18, 2016
59de3fc
a template for PairsEqualToTen
mariotti Nov 18, 2016
13734c3
added shell solution for most frequent int
mariotti Nov 21, 2016
ea9f8cc
shell: moved on awk for portability, make pretty printing and maybe m…
mariotti Nov 22, 2016
58ea16b
adding the rotated list of integers questions
mariotti Nov 23, 2016
c4623e7
added a proposition to create a JSON datafile for the questions
mariotti Nov 28, 2016
3343826
added shell solution to mostFrequentInt
mariotti Nov 28, 2016
0444708
added this fork README file
mariotti Nov 28, 2016
6486285
updates to bugs in isRotated
mariotti Nov 29, 2016
f79a425
provide a new QUESTIONS file as proof for JSON only input
mariotti Nov 29, 2016
28881c1
save a command to create PDFs from root MDs
mariotti Nov 29, 2016
59be66f
replaced QUESTION markdown file with JSON generated
mariotti Nov 30, 2016
a260ab7
adding discussions files to questions md: to test
mariotti Nov 30, 2016
2d62d8b
renamed python solutions
mariotti Nov 30, 2016
8495613
renamed shell solutions
mariotti Nov 30, 2016
87d5753
moved discussions to a single dir
mariotti Nov 30, 2016
e2497f6
solved back compatibility on MD creation
mariotti Dec 3, 2016
0f8fa4d
added one more little tool: Q by category
mariotti Dec 5, 2016
ea2763e
added the json editor from external project
mariotti Dec 5, 2016
88d0b56
testing rawgit for json editor
mariotti Dec 5, 2016
a1403ba
testing rawgit for json editor 02
mariotti Dec 5, 2016
c7e3dfe
first scala example
mariotti Mar 10, 2017
e7ce0e0
added few java and scana exampes
mariotti Mar 13, 2017
13da41f
added the json editor from external project
mariotti Dec 5, 2016
b0e029a
testing rawgit for json editor
mariotti Dec 5, 2016
e714992
testing rawgit for json editor 02
mariotti Dec 5, 2016
c892748
first scala example
mariotti Mar 10, 2017
a70f471
added few java and scana exampes
mariotti Mar 13, 2017
4113543
added the json editor from external project
mariotti Dec 5, 2016
6772210
testing rawgit for json editor
mariotti Dec 5, 2016
39acc6a
testing rawgit for json editor 02
mariotti Dec 5, 2016
499c0a5
Merge branch 'feature/AddJSONeditor' of https://github.com/mariotti/t…
mariotti Mar 13, 2017
8ac0192
Merge branch 'feature/AddJSONeditor' of https://github.com/mariotti/t…
mariotti Mar 13, 2017
80491b1
Merge pull request #8 from mariotti/javascalawork
mariotti Mar 13, 2017
d5244b2
Merge branch 'feature/AddJSONeditor' of https://github.com/mariotti/t…
mariotti Mar 13, 2017
891f84d
Merge pull request #9 from mariotti/javascalawork
mariotti Mar 13, 2017
e37be97
renormalised names
mariotti Mar 30, 2017
1f906f3
from now on only the JSON file is the master data: but we generate th…
mariotti Mar 30, 2017
c6b5c6b
Merge pull request #10 from mariotti/feature/AddJSONeditor
mariotti Mar 30, 2017
2beedbc
Merge pull request #11 from mariotti/javascalawork
mariotti Mar 30, 2017
64d4635
add waffle.io badge
waffle-iron Apr 3, 2017
4dfdeda
Merge pull request #12 from waffle-iron/master
mariotti Apr 3, 2017
3294240
added solution 5 in python
mariotti Apr 10, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,133 changes: 1,133 additions & 0 deletions QUESTIONS.json

Large diffs are not rendered by default.

1,526 changes: 1,358 additions & 168 deletions QUESTIONS.md

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[![Stories in Ready](https://badge.waffle.io/mariotti/technical_interview_questions.png?label=ready&title=Ready)](https://waffle.io/mariotti/technical_interview_questions)
# Technical Interview Questions: interesting problems

This is a repository of interesting (and less interesting) questions with solutions
given in many programming languages and by multiple authors.

As the repository is only at the beginning, we need contributions.

The basic idea is that no algorithm, no code is better then an other.
They are just different: one works better in one case the other better
in an other case.

Consider for example the different sorting algorithms: swap, heap, quick etc.
Each one is the best within its own context.

We can extend it to the programming languages: the same algorithm might
behave differently in one language then on an other, moreover we can have
different implementations for the same solution within the same programming
language.

The target is not to list the best: The target is to give ideas with
examples.

## Current Problems

There are many problems on this repository which I am trying to solve.
If you feel like contributing please let me know

# Current activity

Building a JSON "database" with references to solutions and discussions.

This is already a nice problem ;)

# How to contribute

There are at present many many ways you can contribute. If you feel like just start an issue.

## Language, understanding and related problems

- Even within the short text presented in these pages, there are defintely typos and bad grammar. To contribute you might need to be a bit techky, and not to write a romance or too long correct sentences but any contribution is definitely appreciated. Teaching to tech guys a bit of writing style cannot be too bad.

- I started with a given list of question. Some are not definitely clear. The idea is to create a document for each question in order to describe it better. But some questions are really bad. Please point them out.

## Question, Algo, text and solution

As the starting point is really not tested... the best is:
- Get a question, write a solution if possible or report as not a question.
- Once you are on it write a little document about the question and your solution

## Design this repo

A big contribution and appreciated would be to help in designing better this github repository.
You can start with an issue so that we can start talking.

# Algos ownership

If you wrote a really good algorithm you might want to ask how ownership and copyrights might work.

These are my guidelines:

- The code will be under the repo license which means the latest GPL license.
** We have no meaning to fight for a license so we go for a classical one.
** We also cannot really set up a per algo licensing system right now

- The documentation is indeed under GPL right now, but will require an update to fit better
with a document based license. Of course CC (CreativeCommons) is under consideration. In principle this would
effect the directory: "discussions".

- Ownership: Within git and github there will exist a trace of the author.
But in order to make this explicit I invite you to write for each code you submit
a line like: "#Author: name surname <[email protected]>
and eventually your github member page.
We will try to make this more explicit but for the time being we might need to survive with
git commits authors.
26 changes: 26 additions & 0 deletions bin/generateQmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /bin/sh
#
# This script has a problem on "notes"!! NOT WORKING as expected
# Wrong approach! Need to use jq extensively to generate the md file
echo "# Technical Questions and Algorithms\n"
echo "## List of Categories\n"
./bin/getCategories.sh | sed 's/^"/ - /' | sed 's/"$//'
echo ""
#
cat QUESTIONS.json | jq '.' | awk ' \
/^ *"catname" *:/ {FS = ":";gsub(/^ *" */,"",$2);gsub(/",$/,"",$2);print "#",$2,"\n";} \
/^ *"idC" *:/ {FS = ":";gsub(/^ *" */,"",$2);gsub(/",$/,"",$2);idC=$2;} \
/^ *"idQ" *:/ {FS = ":";gsub(/^ *" */,"",$2);gsub(/",$/,"",$2);idQ=$2;} \
/^ *"idCQ" *:/ {FS = ":";gsub(/^ *" */,"",$2);gsub(/",$/,"",$2);idCQ=$2;} \
/^ *"ID" *:/ {FS = ":";gsub(/^ *" */,"",$2);gsub(/",$/,"",$2);ID=$2;} \
/^ *"notes" *:/ {FS = ":";gsub(/^ *" */,"",$2);gsub(/",$/,"",$2);qnotes=$2;} \
/^ *"name" *:/ {FS = ":";gsub(/^ *" */,"",$2);gsub(/",$/,"",$2);print "##",$2; \
print " -- IDs --";
print " ID Questions:",ID;
print " ID Category:",idC;
print " ID CatQuestions:",idCQ, "\n\n";
print "Inline notes:",qnotes,"\n\n";qnotes=""; \
scmd=sprintf("cat discussions/%s_DISCUSSION.md", ID);\
system(scmd)\
} \
'
3 changes: 3 additions & 0 deletions bin/getCategories.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/sh
cat QUESTIONS.json | jq '.' | jq '.TechQuestions.category[].catname'
#
3 changes: 3 additions & 0 deletions bin/getQuestions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/sh
cat QUESTIONS.json | jq '.' | jq '.TechQuestions.category[].question[].name'
#
14 changes: 14 additions & 0 deletions bin/getQuestionsByCategory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /bin/sh
if [ "${1}a" == "a" ];
then
echo "please give a category name";
echo "Valid categories are:";
./bin/getCategories.sh
exit 0
fi;
qst=${1}
cat QUESTIONS.json | jq '.' | \
jq --arg catname ${qst} '.TechQuestions.category[] | select(.catname==$catname) | .question[].name'
#cat QUESTIONS.json | jq '.' | jq '.TechQuestions.category[] | select(.catname=="Strings") | .question[].name'
# JSON of the CAT: cat QUESTIONS.json | jq '.' | jq '.TechQuestions.category[] | select(.catname=="Strings")'
#
8 changes: 8 additions & 0 deletions bin/makeJSONQuestions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/sh
#
exho "please use now as master file only the QUESTIONS.json"
exit 0
#
./bin/makeJSONfromQ.sh | json_reformat > QUESTIONS.json
./bin/generateQmd.sh > QUESTIONS_N.md
#
24 changes: 24 additions & 0 deletions bin/makeJSONfromQ.QUESTIONS.test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Technical Interview Questions
=============================

**General**
- Find the most frequent integer in an array
- Given 2 integer arrays, determine if the 2nd array is a rotated version of the 1st array.
```Ex. Original Array A={1,2,3,5,6,7,8} Rotated Array B={5,6,7,8,1,2,3}```
- We’re going to find “Word Twins”, which are pairs of English words, at least 4 letters long, where the first three letters of one are the last three letters of another. For example, “strategy” and “Egypt”.
- Given a 3*3 matrix, and 1-8 numbers in random order, 1 place as space.
Write code to find the min exchange of numbers to make the matrix in order.

5 4 1 1 2 3
3 2 ---> 8 4
7 8 6 7 6 5

- There is k parenthesis, write code to calculate how many permutations could have.
For 2 parenthesis, there is 2 permutations: ()() and (()).
- **HARD**: Given a 2D array of 1s and 0s, count the number of "islands of 1s" (e.g. groups of connecting 1s)

**Strings**
- **HARD**: Given a single-line text String and a maximum width value, write the function 'String justify(String text, int maxWidth)' that formats the input text using full-justification, i.e., extra spaces on each line are equally distributed between the words; the first word on each line is flushed left and the last word on each line is flushed right

**Trees**
- Write a function that determines if a tree is a BST
36 changes: 36 additions & 0 deletions bin/makeJSONfromQ.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#! /bin/sh
#
exho "please use now as master file only the QUESTIONS.json"
exit 0
#
QQ="QUESTIONS_OLD.md"
#QQ="bin/makeJSONfromQ.QUESTIONS.test.md"
cat ${QQ} | tail +4 | sed 's/"/``/g' | \
awk 'BEGIN { Ccount=0; Qcount=0; QCcount=0; Ncount=0; firtsC=0; firstQ=0 } \
/^\*\*/ {Ccount++; QCcount=0; gsub(/^\*\*/,"",$0);gsub(/\*\*$/,"",$0);\
if (Ccount >1) \
{print "\t\t\t}\n\t\t]\n\t\t},"}
else {print "{ \"TechQuestions\" :\n\t{ \"category\" :\n\t["}; \
catName=$0;
tagsCnum = split(catName,tagsCname,",");
printf("\t\t{ \"idC\" : \"C%d\", \"catname\" : \"%s\",",Ccount,$0)} \
/^- / {Qcount++; QCcount++; gsub(/^- */,"",$0);gsub(/^ /,"",$0);gsub(/[ ]+$/,"",$0);gsub(/:/,";",$0); if (QCcount >1) {\
if (Ncount > 0) {Ncount = 0;print "\"";}; \
print "\t\t\t},"; \
} \
else { \
print "\n\t\t\"question\" : [ "}; \
printf("\t\t\t"); \
printf("{"); \
printf("\"categoryname\" : \"%s\",",catName); \
printf("\"idC\" : \"C%d\",",Ccount); \
printf("\"idCQ\" : \"C%dQ%d\",",Ccount, QCcount); \
printf("\"idQ\" : \"Q%d\",",QCcount); \
printf("\"ID\" : \"Q%d\",",Qcount); \
printf("\"name\" : \"%s\"",$0); \
} \
/^ / {Ncount++; if (Ncount > 1) \
{gsub(/^[ \t]+/,"",$0);gsub(/[ \t]+$/,"",$0);printf("%s",$0);} \
else {gsub(/^[ \t]+/,"",$0);gsub(/[ \t]+$/,"",$0);printf("\t\t\t,\n\t\t\t\"notes\" : \"%s",$0)}}
END { print "\t\t\t}\n\t\t]\n\t\t}\n\t]\n}\n}"}'
#
5 changes: 5 additions & 0 deletions bin/makeRootPDF.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /bin/sh
#
pandoc -t latex -o README.pdf README.md
pandoc -t latex -o QUESTIONS.pdf QUESTIONS.md
#
Empty file added discussions/.placeholder
Empty file.
49 changes: 49 additions & 0 deletions discussions/Q1_DISCUSSION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
### Bare Question

Find the most frequent integer in an array

### Discussion

#### Questions

- What if there is more then one answer? If few integers have the same highest frequency.
- How to report the results?

### Algorithms

#### Accumulate frequency count

The first algorithm simply sets up independent "counters" for each number, then it search
for the max value within the counters.

Pros: The data can be reused and inspected. For example checking same ranking or lower
ranking.

Cons: It has to be stored in memory to be useful.

##### Python Solution

It can be implemented as a dictionary, which is the straight forward solution in python.
Namely Key/Values pairs for the sake of the algorithm.

#### Sort and count

This algorithm is fully based on sorting. It is useful if the data are already "almost"
sorted. Once the data are sorted it simply counts the data repetition and gives the highest
number found.

Pros: Fast on sorted or almost sorted data. Can be modified to get the second or third result.
It uses no memory except for the sorting.

Cons: it has no history of the data and results.

##### Python Solution

##### Shell Solution

### Real Case examples

#### Find the most viewed movie
[mariotti] I had a similar case in the analysis of movielens data. The solution was similar
to the sorting and counting algorithm. This was for data analysis and not for production.

22 changes: 22 additions & 0 deletions discussions/Q2_DISCUSSION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Bare Question

Find pairs in an integer array whose sum is equal to 10 (bonus: do it in linear time)

### Discussion

#### Questions

- Is the array exclusive? i.e. do I have to find the unique pairs?
- How do I have to handle this case: [3, 7, 7]? One pair or 2?

### Algorithms

#### ALgo one



### Real Case examples

#### Find pair matches


Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions java_solutions/Q3_isRotated.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#From: http://stackoverflow.com/questions/2553522/interview-question-check-if-one-string-is-a-rotation-of-other-string
# Answer from: comunity wiki
# a litteral copy
# Just a java started
#
#algorithm checkRotation(string s1, string s2)
# if( len(s1) != len(s2))
# return false
# if( substring(s2,concat(s1,s1))
# return true
# return false
#end
#

boolean isRotation(String s1,String s2) {
return (s1.length() == s2.length()) && ((s1+s1).indexOf(s2) != -1);
}

48 changes: 48 additions & 0 deletions libs/json-editor/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Contributing
===============
This document briefly lists the guidelines for contributing to JSON Editor.

Reporting Bugs
----------------
When creating an issue in GitHub, try to include when feasible:
* A brief description of the issue
* An example JSON schema that causes the issue
* Steps to reproduce

If you can reproduce the issue on the demo page (http://jeremydorn.com/json-editor/), it's helpful to attach the "Direct Link" url (top right of page). Note: the direct link might not work for very large schemas or JSON values.


Contributing Code
--------------------------
One of the major goals of JSON Editor is to be easy to modify and hack.

If you fix a bug or add a cool feature, please submit a pull request!


### Code Style

* Use 2 spaces for indentation
* Use comments whenever the code's meaning is not obvious
* When in doubt, try to match the style in existing source files

###Grunt

The easiest way to hack on JSON Editor is to run `grunt watch`, which
re-builds `dist/jsoneditor.js` every time a source file changes.

To do a full grunt build which includes jshint and minification, run `grunt`.

### Submitting Pull Requests
Try to limit pull requests to a single narrow feature or bug fix.

__Do not submit `dist/` files!__

The following is done when a pull request is accepted. There is no need to do any of these steps yourself.

1. Merge pull request into master
2. Increment version number in `src/intro.js` and `bower.json`. Set date in `src/intro.js`.
3. Build `dist/` files with grunt
4. Commit and push to github
5. Add a git tag and release for this version with a short changelog

Sometimes, multiple pull requests will be merged before doing steps 2-5.
Loading