Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T1
{
    class Pad
    {
        public int digit;
        public char[] letter;
    }

    class Test1
    {
        private HashSet<string> words = new HashSet<string>();
        private int[] phoneNumber;
        private Pad[] pad;

        public Test1()
        {
            words.Add("what");
            words.Add("this");
            words.Add("nothing");
            words.Add("aran");

            phoneNumber = new int[] { 7, 0, 1, 8, 2, 3 };

            pad = new Pad[4];

            pad[0] = new Pad();
            pad[0].digit = 1;
            pad[0].letter = new char[] { 'a', 'w', 't' };

            pad[1] = new Pad();
            pad[1].digit = 2;
            pad[1].letter = new char[] { 'r', 'w', 'h' };

            pad[2] = new Pad();
            pad[2].digit = 3;
            pad[2].letter = new char[] { 'a', 'n', 'f' };

            pad[3] = new Pad();
            pad[3].digit = 4;
            pad[3].letter = new char[] { 'n', 'j', 't' };
        }

        public void FindOneWord(int[] letters)
        {
            string prototype = "";
            int nWhich = 0;
            foreach (int position in phoneNumber)
            {
                if (position >= 0 && position < pad.Length)
                {
                    prototype += pad[position].letter[letters[nWhich]];
                    ++nWhich;
                }
            }
            if (words.Contains(prototype))
            {
                Console.WriteLine(prototype);
            }
        }

        public void FindAllWords()
        {
            int[] letters = { 0, 0, 0, 0 };
            for (int counter = 0; counter <= 2222; ++counter)
            {
                int k3 = counter % 10;
                int k2 = (counter % 100) / 10;
                int k1 = (counter % 1000) / 100;
                int k0 = (counter % 10000) / 1000;

                if (k3 >= 3) continue;
                if (k2 >= 3) continue;
                if (k1 >= 3) continue;
                if (k0 >= 3) continue;

                //Console.Write(k0);
                //Console.Write(k1);
                //Console.Write(k2);
                //Console.Write(k3);
                //Console.WriteLine();

                letters[0] = k0;
                letters[1] = k1;
                letters[2] = k2;
                letters[3] = k3;

                FindOneWord(letters);
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Test1 t1 = new Test1();
            t1.FindAllWords();
        }
    }
}

- Anonymous November 24, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T1
{
    class Pad
    {
        public int digit;
        public char[] letter;
    }

    class Test1
    {
        private HashSet<string> words = new HashSet<string>();
        private int[] phoneNumber;
        private Pad[] pad;

        public Test1()
        {
            words.Add("what");
            words.Add("this");
            words.Add("nothing");
            words.Add("aran");

            phoneNumber = new int[] { 7, 0, 1, 8, 2, 3 };

            pad = new Pad[4];

            pad[0] = new Pad();
            pad[0].digit = 1;
            pad[0].letter = new char[] { 'a', 'w', 't' };

            pad[1] = new Pad();
            pad[1].digit = 2;
            pad[1].letter = new char[] { 'r', 'w', 'h' };

            pad[2] = new Pad();
            pad[2].digit = 3;
            pad[2].letter = new char[] { 'a', 'n', 'f' };

            pad[3] = new Pad();
            pad[3].digit = 4;
            pad[3].letter = new char[] { 'n', 'j', 't' };
        }

        public void FindOneWord(int[] letters)
        {
            string prototype = "";
            int nWhich = 0;
            foreach (int position in phoneNumber)
            {
                if (position >= 0 && position < pad.Length)
                {
                    prototype += pad[position].letter[letters[nWhich]];
                    ++nWhich;
                }
            }
            if (words.Contains(prototype))
            {
                Console.WriteLine(prototype);
            }
        }

        public void FindAllWords()
        {
            int[] letters = { 0, 0, 0, 0 };
            for (int counter = 0; counter <= 2222; ++counter)
            {
                int k3 = counter % 10;
                int k2 = (counter % 100) / 10;
                int k1 = (counter % 1000) / 100;
                int k0 = (counter % 10000) / 1000;

                if (k3 >= 3) continue;
                if (k2 >= 3) continue;
                if (k1 >= 3) continue;
                if (k0 >= 3) continue;

                //Console.Write(k0);
                //Console.Write(k1);
                //Console.Write(k2);
                //Console.Write(k3);
                //Console.WriteLine();

                letters[0] = k0;
                letters[1] = k1;
                letters[2] = k2;
                letters[3] = k3;

                FindOneWord(letters);
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Test1 t1 = new Test1();
            t1.FindAllWords();
        }
    }
}

- Anonymus November 24, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// Shows the full declarative power of ZoomBA
tel_dict = { 2 : [ 'a','b','c' ] , 3 : ['d' ,'e' ,'f' ],
             4 : [ 'g' , 'h' ,'i' ], 5 : [ 'j', 'k', 'l' ],
             6 : ['m','n','o'  ], 7 : [ 'p', 'q','r' ,'s' ],
             8 : [ 't' ,'u','v' ], 9 : [  'w' , 'y' ,'z' ] }
// meaningful words?
words = select( file('/usr/share/dict/words') ) :: { #|$.o| == 7  } -> { $.o.toLowerCase }
ph_no = 2742538 // your input : cricket
args = list( str(ph_no).value ) -> { tel_dict[ int($.o) ] }
meaningful = join( @ARGS = args ) :: {
    word = str( $.o ,'' )
    word @ words } -> { str( $.o ,'' ) }
println ( meaningful )

- NoOne November 24, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def find_all_words(prefix, current_alphabet, more_alphabets):
    next_alphabet = more_alphabets[0] if len(more_alphabets) >= 1 else []
    words = set([prefix]) if not current_alphabet else set()
    for letter in current_alphabet:
        words |= find_all_words(prefix + letter, next_alphabet,
                                more_alphabets[1:])
    return words

if __name__ == '__main__':
    num_pad = {2: ['a', 'b', 'c'], 3: ['d', 'e', 'f'],
               4: ['g', 'h', 'i'], 5: ['j', 'k', 'l'],
               6: ['m', 'n', 'o'], 7: ['p', 'q', 'r', 's'],
               8: ['t', 'u', 'v'], 9: ['w', 'y', 'z']}
    phone_number = '7899533'
    alphabets = [num_pad[int(num)] for num in phone_number]
    # word list from github
    real_words = set(open('words.txt', 'r').read().splitlines())
    created_words = find_all_words('', alphabets[0], alphabets[1:])
    print [word for word in created_words if word in real_words]

- littlefinger November 24, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More