TalkIQ Interview Question for Senior Software Development Engineers


Country: Canada
Interview Type: In-Person




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

public int howmany(int[] given, int k) {
        int total =0;

        for (int n : given) {
            total = n== 0 && k == n ? total +1: total;
            while (n > 0) {
                total = n %10 == k ? total +1: total;

                n /= 10;
            }
        }

        return total;
    }

- smaharj1@ramapo.edu September 06, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Arrays;
import java.util.List;

/**
 *
 * @author vensi
 */
public class CountDigitList {

    public static void main(String[] args) {
        // Conventional way
        List<Integer> l = Arrays.asList(0, 100, 20, 44, 56, 64, 79);
        int k = 4;
        int totalCount = 0;
        for (int i : l) {
             totalCount+=countDigitInNumber(k,i);
        }
        System.out.println(totalCount);
        
        //Using java 8 streams and Strings
        String s = l.parallelStream().map(a->a.toString()).reduce("",(a,b)->a.concat(b));
        System.out.println(s.length() - s.replace(k+"", "").length());
    }

    private static int countDigitInNumber(int digit, int number) {
        int count = 0;
        do {
            int remainder = number % 10;
            number = number / 10;
            if (digit == remainder) {
                count++;
            }
        } while (number > 0);
        return count;
    }
}

- kamaldheeraj September 08, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
public class TestDemo
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int n = input.nextInt(); //total numbers in the list L
		int k = input.nextInt(); //the value to count
		String[] array = new String[n]; //list of numbers goes here
		String totalString = " ";
		for(int i = 0;i<n;i++)
		{
			array[i]=input.next();
			totalString = totalString + array[i];
		}
		//now you have a string for all the list numbers
		char[] arrayOfTotalString = totalString.toCharArray();
		int count = 0;
		for(int i = 0;i<totalString.length();i++)
		{
			if(k==Character.getNumericValue(arrayOfTotalString[i]))
			{
				count++;
			}
		}
		System.out.println(count);  //final count
	}
}

}

- Wolvie September 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
public class TestDemo
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
int n = input.nextInt(); //total numbers in the list L
int k = input.nextInt(); //the value to count
String[] array = new String[n]; //list of numbers goes here
String totalString = " ";
for(int i = 0;i<n;i++)
{
array[i]=input.next();
totalString = totalString + array[i];
}
//now you have a string for all the list numbers
char[] arrayOfTotalString = totalString.toCharArray();
int count = 0;
for(int i = 0;i<totalString.length();i++)
{
if(k==Character.getNumericValue(arrayOfTotalString[i]))
{
count++;
}
}
System.out.println(count); //final count
}
}

- Wolvie September 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
using namespace std;
int main()
{
int t,n,i;
cin>>t;
while(t--){
cin>>n;
int a[n],c=0,k;
for(i=0;i<n;i++)
cin>>a[i];
cin>>k;
for(i=0;i<n;i++){
while(a[i]){
if(a[i]%10==k)
c++;
a[i]/=10;
}
}
cout<<c<<endl;
}
}

- SAHA HINLEY SHRUNG September 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class AppTest
{

	public static void main(String[] args)
	{
		int[] k = {0, 3, 9};
		int[] l = {0, 45, 3900, 9};
		for (int ek : k)
			System.out.println(ek + " : " + howmany(l, ek));
	}

	public static int howmany(int[] L, int k)
	{
		int total = 0;
		for (int l: L) {
			if (l == 0 && l == k)
				total++;
			if (l > 0) {
				String strL = String.valueOf(l);
				for (int i = 0; i < strL.length(); i++) {
					if (Character.getNumericValue(strL.charAt(i)) == k)
						total++;
				}
			}
		}
		return total;
	}
}

- bti September 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

In python3

import re

L = list(map(str,input().split()))

k = int(input())

string = "".join(L)

getNo = re.findall(str(k),string)

print(len(getNo))

- rehanshikkalgar September 05, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

First time submitter, but here goes nothing.

int frequencyCount (int[] list, int k)
{
int[] countlist = new int[10];
	for (int i = 0; i < list.length; i++)
	{
	int newK = list[i];
		while(newK > 9)
		{
		countlist[newK % 10]++;
		newK = newK  / 10;
		}
	countlist[newK]++;
	}
return countlist[k];
}

- Gman September 05, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Unfortunately I have only relatively slow O(list.length * digits in each list member) solution to the problem. Inside my algorithm there is a for loop that for every number in a collection calls another function countDigit(int n, int digit) that counts how many times digit appears in that number. countDigit is recursive function with O(digits in number) complexity.

import java.util.*;

public class Example{
    
    public static int countDigit(int n, int digit)
    {
        if(n == digit)return 1;
        if(n == 0 && n != digit)return 0;
        if(n % 10 == digit)
        {
            return 1 + countDigit(n/10, digit);
        }else
        {
            return 0 + countDigit(n/10, digit);
        }
        //for example n = 3242 digit = 2;
        //1. 3242 % 10 == 2 so return 1 + countDigit(3242/10, 2)
        //2. 324 % 10 != 2 so return 0 + countDigit(324/10, 2)
        //3. 32 % 10 == 2 so return 1 + countDigit(32/10, 2);
        //4. 3 % 10 != 2 so return 0 + countDigit(3/10, 2);
        //5. 0 == base case so return 0;
        //countDigit = cD
        //cD(3242, 2) = 1 + cD(324, 2); cd(3242, 2) = 1 + 0 + cD(32, 2);
        //cd(3242, 2) = 1 + 0 + 1 + cd(3, 2); cd(3242, 2) = 1+0+1+cD(0, 2) = 1+0+1+0 = 2;
    }
    
    public static int howMany(List<Integer> list, int digit)
    {
        int counter = 0;
        for(int number : list)
        {
            counter += countDigit(number, digit);
        }
        return counter;
    }

     public static void main(String []args){
        List<Integer> list = new ArrayList<Integer>();
        list.add(2);
        list.add(12);
        list.add(245);
        list.add(34);
        list.add(764);
        list.add(2227); 
        list.add(324262);
        
        int number = 2;
        
        System.out.println("In list there are " + howMany(list,  number) + " digits equals " + number);
        //In list there are 9 digits equals 2
     }
}

- bogdan.zima September 05, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

ll = new Array(10).fill(0);

function add(aa){
ll[aa]++;
}

function spl(a){
s=a.split("");
// document.write(s[0]+" "+ll[1]+" ");
s.forEach(add);
}

var lists = ["12","1"];

lists.forEach(spl);

document.write(ll);

- Baradwaj Aryasomayajula September 05, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Flattening the number list to string and iterating over it.
In Python:

flat_L = ''.join(str, L)
k_occurrences = [0] * 10
for num in flat_L:
  k_occurrences[int(num)] += 1

Here L is the initial list with integer values;
k_occurrences - list where index represent the k number; and value represents the occurrences

- paul.sukys September 06, 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