AG Interview Assessment


Challenge Summary:

Overview

In real world, you are always going to have to solve complex problems as a developer.

You will be given a few challenges below, from beginner to medium difficulties.

It’s meant to assess your programming skills and give us an idea of how you tackle real-world application challenges (Research & Analysis, Develop, Testing, Debug, Deployment, Documentation).

You will be given 1 week to complete the assessment.

Complete all the tasks with C# only.

Challenges

#1 Question

    Given a text file file.txt that contains a list of phone numbers (one per line), write a one-liner bash script to print all valid phone numbers.

    You may assume that a valid phone number must appear in one of the following two formats: (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit)

    You may also assume each line in the text file must not contain leading or trailing white spaces.

    Example:

    Assume that file.txt has the following content:

    987-123-4567 123 456 7890 (123) 456-7890

    Your script should output the following valid phone numbers:

    987-123-4567 (123) 456-7890

    Boilerplate (start with this code)

    // Warm up question only #YOLO.


#2 Question

    Create a function to check if a candidate is qualified in an imaginary coding interview of an imaginary tech startup.

    The criteria for a candidate to be qualified in the coding interview is:

    1. The candidate should have complete all the questions.
    2. The maximum time given to complete the interview is 120 minutes.
    3. The maximum time given for very easy questions is 5 minutes each.
    4. The maximum time given for easy questions is 10 minutes each.
    5. The maximum time given for medium questions is 15 minutes each.
    6. The maximum time given for hard questions is 20 minutes each.
    7. If all the above conditions are satisfied, return "qualified", else return "disqualified".

    You will be given an array of time taken by a candidate to solve a particular question and the total time taken by the candidate to

    complete the interview.

    Given an array, in a true condition will always be in the format very easy, very easy, easy, easy, medium, medium, hard, hard.

    The maximum time to complete the interview includes a buffer time of 20 minutes.

    Examples:

    Interview(new int [] { 5, 5, 10, 10, 15, 15, 20, 20 }, 120) ➞ "qualified" Interview(new int [] { 2, 3, 8, 6, 5, 12, 10, 18 }, 64) ➞ "qualified" Interview(new int [] { 5, 5, 10, 10, 25, 15, 20, 20 }, 120) ➞ "disqualified" // Exceeded the time limit for a medium question. Interview(new int [] { 5, 5, 10, 10, 15, 15, 20 }, 120) ➞ "disqualified" // Did not complete all the questions. Interview(new int [] { 5, 5, 10, 10, 15, 15, 20, 20 }, 130) ➞ "disqualified" // Solved all the questions in their respected time limits but exceeded the total time limit of the interview.

    Boilerplate (start with this code):

    using System; public class Program { public static string Interview(int[] arr, int tot) { } }


#3 Question

    Write a function that returns all sets of three elements that sum to 0.

    Examples

    ThreeSum(new int[] { 0, 1, -1, -1, 2 }) ➞ { { 0, 1, -1 }, { -1, -1, 2 } } ThreeSum(new int[] { 0, 0, 0, 5, -5 }) ➞ { { 0, 0, 0 }, { 0, 5, -5 } } ThreeSum(new int[] { 1, 2, 3 }) ➞ { } ThreeSum(new int[1]) ➞ { }

    Notes
    • The original array may contain duplicate numbers.
    • Each three-element subarray in your output should be distinct.
    • Subarrays should be ordered by the first element of the subarray.
    • Subarrays themselves should be ordered the same as the original array.
    • Return an empty array if no three elements sum to zero.
    • Return an empty array if there are fewer than three elements.

    Boilerplate (start with this code)

    // The following libraries may be useful using System; using System.Linq; using System.Collections.Generic; public class Program { public static List<int[]> ThreeSum(int[] arr) { return new List<int[]>( ); } }


#4 Question

    Write a sorting function that takes in an array of names and sorts them by last name either alphabetically (ASC) or reverse-alphabetically (DESC).

    Examples

    SortContacts(new string[] { "John Locke", "Thomas Aquinas", "David Hume", "Rene Descartes" }, "ASC") ➞ { "Thomas Aquinas", "Rene Descartes", "David Hume", "John Locke" } // Aquinas (A) < Descartes (D) < Hume (H) < Locke (L) SortContacts(new string[] { "Paul Erdos", "Leonhard Euler", "Carl Gauss" }, "DESC") ➞ { "Carl Gauss", "Leonhard Euler", "Paul Erdos" } // Gauss (G) > Erdos (ER) > Euler (EU) SortContacts([], "DESC") ➞ {} SortContacts(null, "DESC") ➞ {}

    Notes
    • An array with a single name should be trivially returned.
    • An empty array, or an input of null should return an empty array.

    Boilerplate (start with this code)

    using System; public class Program { public static string[] SortContacts(string[] names, string sort) { return new string[0]; } }


#5 Question

    Throwing Amount of Darts Find All Possible Combinations to Reach a Target Score

    You're given a dartboard divided into sections, each section has a unique score. That means there won't be two sections with the same score.


    Throwing a certain amount of valid darts, find how many solutions there are to reach the target score. Your function will be passed three parameters...

    • Sections: A list of values for the sections (e.g. { 3, 6, 8, 11, 15, 19, 22 }, the list is already sorted).
    • Darts: The amount of darts to throw.
    • Target: The target score.

    Examples

    If there are duplicate values, keep only the one sorted from smallest to biggest.

    "8-19-8" "8-8-19" <-- This is the one you would keep. "19-8-8"

    Multiple solutions should be sorted before returning them.

    { "3-11-18", "7-7-18", "7-11-14" } is ok. { "7-11-14", "7-7-18", "3-11-18" } is not ok.

    Notes
    • Multiple darts can land in the same section.
    • A dart must land in a valid section (it can't miss).

    Boilerplate (start with this code)

    // Its possible to solve using some or all of these librarys. using System; using System.Text; using System.Text.RegularExpressions; using System.Collections; using System.Collections.Generic; using System.Linq; public class Program { public static string[] DartsSolver(int[] sections, int darts, int target) { return new string[0]; } }


#6 Question

    In this challenge, you have to establish which kind of Poker combination is present in a deck of five cards. Every card is a string containing the card value (with the upper-case initial for face-cards) and the lower-case initial for suits, as in the examples below:

    "Ah" ➞ Ace of hearts "Ks" ➞ King of spades "3d" ➞ Three of diamonds "Qc" ➞ Queen of clubs "10c" ➞ Ten of clubs

    Name Description
    Royal FlushA, K, Q, J, 10, all with the same suit.
    Straight FlushFive cards in sequence, all with the same suit.
    Four of a KindFour cards of the same rank.
    Full HouseThree of a Kind with a Pair.
    FlushAny five cards of the same suit, not in sequence.
    StraightFive cards in a sequence, but not of the same suit.
    Three of a KindThree cards of the same rank.
    Two PairTwo different Pair.
    PairTwo cards of the same rank.
    High CardNo other valid combination.

    Given an array hand containing five strings being the cards, implement a function that returns a string with the name of the highest combination obtained, accordingly to the table above.

    Examples

    If there are duplicate values, keep only the one sorted from smallest to biggest.

    PokerHandRanking({ "10h", "Jh", "Qh", "Ah", "Kh" }) ➞ "Royal Flush" PokerHandRanking({ "3h", "5h", "Qs", "9h", "Ad" }) ➞ "High Card" PokerHandRanking({ "10s", "10c", "8d", "10d", "10h" }) ➞ "Four of a Kind"

    Multiple solutions should be sorted before returning them.

    Notes

    N/A

    Boilerplate (start with this code)

    using System; using System.Linq; public class Program { public static string PokerHandRanking(string[] hand) { return string.Empty; } }


*Compulsory*

  • Document everything: Explain your solution (Can be in any form: video, doc, screenshot, etc)
  • Git commit for each solution
  • Register an account here https://gitlab.agsmartit.com upload your source code to AG GitLab