Skip to content

Instantly share code, notes, and snippets.

@mariotti
Created November 28, 2016 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariotti/6705ee0771de0fe42a7d6b7ef15912c6 to your computer and use it in GitHub Desktop.
Save mariotti/6705ee0771de0fe42a7d6b7ef15912c6 to your computer and use it in GitHub Desktop.
make json from markdown - markdown to json
#! /bin/sh
#
QQ="QUESTIONS.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\", \"name\" : \"%s\",",Ccount,$0)} \
/^- / {Qcount++; QCcount++; 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}"}'
#
@mariotti
Copy link
Author

This snippet translates a "specific" markdown file into a JSON data file. As in the actual project this file will disappear I thought to save it as gist.

The file in question is:

https://github.com/mariotti/technical_interview_questions/blob/master/QUESTIONS.md

A short version is:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment