Documents

Algo Questions

Description
Good questions on programming
Categories
Published
of 19
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
  Backend and Frontend Dev Test Below is our test for prospective developers. If you’re applying for a Frontend development position, we consider the CSS, HT! and avascript sections to #e particularly important. If you’re applying for a Bac$end development position, we consider the %lgorithms, &evelopment and yS'! sections to #e particularly important. (e use )H) and )ython for server*side code, #ut you can answer these +uestions in the language of your choice if you do not $now these languages well.(e favor accuracy highly, and we’d rather you answer fewer +uestions with greater accuracy than more +uestions with less accuracy. The +uestions #ecome progressively harder through each section. If you’re applying for a Full Time position, we epect you to #e a#le to answer the last +uestions in most sections relevant for the position you’re applying -Frontend or Bac$end. If you’re applying for an Internship, doing the same would #e great #ut not re+uired. a$e sure the code you send is functional, and does not have synta errors. /sing search engines and online documentation is strongly encouraged.)lease fill the answers in this document.0ood luc$1 [All] 0. Candidate details )lease fill in the following information * when applies * so we $now you #etter.2 [Backend] 1. Object-oriented prograing! algorit s 3.(hat is your favorite programming language and why4 Javascript is my favorite programming language due to the expressiveness accorded by the language owing to its functional nature. 5.(hat difference is there #etween class and instance varia#les4 Class variables are shared across all instances of a class while an instance variable is applicable for a particular instance only. 6.&etail the steps of the Bu##le sort algorithm applied to the following vector7 [“celery”, “carrot”, “cabbage”, “tomato”]ubble sort is done by repeatedly iterating through the vector, comparingeach pair of ad!acent elements and swapping them if they are in the wrongorder. he list is repeated iterated till no more swaps are needed which indicates that the list is sorted. he vector will be sorted in alphabetic order. he elements being compared will be highlighted in bold and underlined. #irst $ass  %%%%%%%%%%[& celery    &, “carrot”,  “cabbage”, “tomato”] %' [ “carrot”, & celery   &, “cabbage”, “tomato”][ “ carrot ”, celery , “cabbage”,    “tomato”] %' [“carrot”, cabbage , “celery”,    “tomato”][“carrot”, &cabbage&, “celery”, “tomato”   ] %' [“carrot”, &cabbage&, “celery”, “tomato”   ](econd $ass %%%%%%%%%%% [ “carrot”, cabbage   , “celery”, “tomato”] %' [& cabbage , carrot   , “celery”, “tomato”] [&cabbage&, carrot , “celery”   , “tomato”] %' [&cabbage&, carrot , “celery”   , “tomato”] [&cabbage&, &carrot&, “celery”, “tomato”   ] %' [&cabbage&, &carrot&, “celery”, “tomato”   ]  hird $ass %%%%%%%%%%   [& cabbage , carrot ,    “celery”, “tomato”] %' [& cabbage , carrot ,    “celery”, “tomato”] [&cabbage&, carrot , “celery”,    “tomato”] %' [&cabbage&, carrot , “celery”,    “tomato”] [&cabbage&, &carrot&, “celery”, “tomato”   ] %' [&cabbage&, &carrot&, “celery”, “tomato”   ] 8.(e consider an array %93...n:. (rite a function that returns -the largest difference in the array #etween a value and another value with a smaller inde int max)ifference*int[] arr+  int max)iff - arr[] / arr[0] 1 int min2umber - arr[0] 1 for*int i -  1 i 3 arr.length 1 i44+  int diff - a[i] / min2umber 1 if*diff ' max)iff+  max)iff - diff 1 5 if*a[i] 3 min2umber+  min2umber - a[i] 1 5 5 return max)iff 15 ime complexity - 6*n+ ;.%n array %93....n: is said to have a ma<ority element if more than half of its entries are the same. 0iven an array, design an efficient algorithm to tell whether the array has a ma<ority element, and, if so, to find that element. The elements of the array are not necessarily from some ordered domain li$e the integers, and so there can #e no comparisons of the form =is %9i: > %9<:4=. However you can answer +uestions of the form7 =is %9i: ? %9<:4= in constant time. 7e can achieve this in two steps each with 6*n+ complexity.8n the first step we iterate through the array, cancelling out each occurance of an element e with all the other elements that are different from e then e will exist till the end if it is a ma!ority element.8n the second step we !ust iterate through the array, counting each occurance of the ma!ority element found in step . 8f the count is more than n9:, where n is the si;e of the array, then we have a ma!ority element.  (tep  / #ind a probable ma!ority candidate in an array a %%%%%% . 8nitialise ma!ority element index and count. ma!<lem8ndex - 0 and count -  :. =oop for i -  to length of array /  *a+ if*a[ma!<lem8ndex] -- a[i]+ count44 *b+ <lse count%% *c+ if*count -- 0+ ma!<lem8ndex - i count -  >. ?eturn a[ma!<lem8ndex] (tep : / @erify if ma!ority element obtained in step  is indeed ma!ority %%%%%%% . 8nitialise count - 0 and ma!ority<lement - value from (tep  :. =oop for i -  to length of array /  *a+ if*ma!ority<lement -- a[i]+ count44 >. 8f count ' *length of array 9 :+ print ma!ority element else print none.   [Backend] #. $rograing 3.0ive a regular epression that detects headecimal num#ers in a tet, for eample @AAf8’, @Aacdadecf55eeff65aca;6Ae86c#;8aa55e6’, @B%&FAA&’ should #e detected. Bonus points for writing a test case. ?egular <xpression in !ava A*0x+B*Bi+[dD%#]4Eimport !unit.frameworF. estCase1import !ava.util.regex.$attern1import !ava.util.regex.Gatcher1public class Hexadecimal est extends estCase  public Hexadecimal est*(tring test2ame+  super*test2ame+1 5 (tring[] testHexa)ata - &0x0fI&, &0acdadecf::eeff>:acaK>0eI>cbKIaaL::e>&, &D)#00)&51 (tring[] test2otHexa)ata - &0x0fIm&, &0aLLvMcaK>0eI>cbK&, &D)#66)&51 $attern pattern1 public void setN$*+  pattern - $attern.compile*&A*0x+B*Bi+[dD%#]4E&+1 5 public void testHexa*+  for*int i - 01 i 3 testHexa)ata.length1 i44+  (tring message - testHexa)ata[i] 4 &is Hexadecimal&1 assert<Ouals*message, true, isHexa*testHexa)ata[i]++1 5 5 public void test2otHexa*+  for*int i - 01 i 3 test2otHexa)ata.length1 i44+  (tring message - test2otHexa)ata[i] 4 &is not Hexadecimal&1 assert<Ouals*message, false, isHexa*test2otHexa)ata[i]++1 5 5
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks