Programming challenges I use to hire Programmers

Prasad Ajinkya

Prasad Ajinkya

@prasad-aSUfhP Oct 22, 2024
Whenever I hire programmers, I prefer to give them programming tasks within the interview, or before coming to the interview. I thought that I might share this with fellow CEans, I generally use problems from Project Euler as programming challenges.

For.e.g <a href="https://projecteuler.net/problem=1" target="_blank" rel="nofollow noopener noreferrer">#1 Multiples of 3 or 5 - Project Euler</a>

This is the simplest problem there. Check out some of the other problems, it is the perfect test for comp. sci. engineers, since not only does this test your logic writing skills but also it tests your knowledge of your favorite programming language!!

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • K!r@nS!ngu

    K!r@nS!ngu

    @kr-at-nsngu-XqzcfU Jan 15, 2012

    Java code:


    public class Add
    {
    public static void main(String[] args)
    {
    int sum=0;
    int num = 0;
    System.out.println("This Java program will add all the natural numbers below one thousand that are multiples of 3 or 5.");
    while(num<999)
    {
    num++;
    if(num%3 == 0 || num%5 == 0)
    {
    sum=sum+num;
    }
    }
    System.out.println("Sum is: "+ sum);
    }
    }


    I like these kind of programming tasks. can you give more ?
  • vinci

    vinci

    @vinci-e4PtMU Jan 15, 2012

    nice puzzle .how can we do this-
    write any number-
    2
    you wrote-two

    in java ??How is this possible i still dont know
  • K!r@nS!ngu

    K!r@nS!ngu

    @kr-at-nsngu-XqzcfU Jan 15, 2012

    vinci
    nice puzzle .how can we do this-
    write any number-
    2
    you wrote-two

    in java ??How is this possible i still dont know

    It's simple. we have to create a scanner object and take input. Re-printing the number pretty easy 😀 Let me try and give the code.
  • K!r@nS!ngu

    K!r@nS!ngu

    @kr-at-nsngu-XqzcfU Jan 15, 2012

    Here is the code:

    import java.util.Scanner;
    public class Number
    {
    public static void main(String args[])
    {
    Scanner input=new Scanner(System.in);
    int number;
    System.out.print( "Enter any number: " );
    number=input.nextInt();
    System.out.printf( "You have entered:%d ",number );
    }
    }
  • vinci

    vinci

    @vinci-e4PtMU Jan 15, 2012

    i think you didnt understood the whole puzzle i posted.When user enters integers,its output must be in words.like if i enter 100,so output must be "one hundred"
  • K!r@nS!ngu

    K!r@nS!ngu

    @kr-at-nsngu-XqzcfU Jan 15, 2012

    vinci
    i think you didnt understood the whole puzzle i posted.When user enters integers,its output must be in words.like if i enter 100,so output must be "one hundred"
    Oops..😕 let me give a one more trail....
  • K!r@nS!ngu

    K!r@nS!ngu

    @kr-at-nsngu-XqzcfU Jan 15, 2012

    Bro. Finally got it after taking help from Google.
    Concept is simple:
    1. Analyzing the input(counting no. of digits).
    2. Converting to string based on no. of digits in the input.
    Code is :

    import java.lang.*;
    import java.io.*;
    import java.util.*;
    class constNumtoLetter{
    String[] unitdo ={"", " One", " Two", " Three", " Four", " Five",
    " Six", " Seven", " Eight", " Nine", " Ten", " Eleven", " Twelve",
    " Thirteen", " Fourteen", " Fifteen", " Sixteen", " Seventeen",
    " Eighteen", " Nineteen"};
    String[] tens = {"", "Ten", " Twenty", " Thirty", " Forty", " Fifty",
    " Sixty", " Seventy", " Eighty"," Ninety"};
    String[] digit = {"", " Hundred", " Thousand", " Lakh", " Crore"};
    int r;
    //Count the number of digits in the input number
    int numberCount(int num){
    int cnt=0;
    while (num>0){
    r = num%10;
    cnt++;
    num = num / 10;
    }
    return cnt;
    }
    //Function for Conversion of two digit
    String twonum(int numq){
    int numr, nq;
    String ltr="";
    nq = numq / 10;
    numr = numq % 10;
    if (numq>19){
    ltr=ltr+tens[nq]+unitdo[numr];
    }
    else{
    ltr = ltr+unitdo[numq];
    }
    return ltr;
    }
    //Function for Conversion of three digit
    String threenum(int numq){
    int numr, nq;
    String ltr = "";
    nq = numq / 100;
    numr = numq % 100;
    if (numr == 0){
    ltr = ltr + unitdo[nq]+digit[1];
    }
    else{
    ltr = ltr +unitdo[nq]+digit[1]+" and"+twonum(numr);
    }
    return ltr;
    }
    }
    class ActiveMQSwing{
    public static void main(String[] args){
    try
    {
    //Defining variables q is quotient, r is remainder
    int len, q=0, r=0;
    String ltr = " ";
    String Str = "You have entered";
    constNumtoLetter n = new constNumtoLetter();
    System.out.println("Enter number");
    Scanner input=new Scanner(System.in);
    int num = input.nextInt();
    if (num <= 0)
    System.out.println("Zero or Negative number not for conversion");
    while (num>0){
    len = n.numberCount(num);
    //Take the length of the number and do letter conversion
    switch (len){
    case 8:
    q=num/10000000;
    r=num%10000000;
    ltr = n.twonum(q);
    Str = Str+ltr+n.digit[4];
    num = r;
    break;
    case 7:
    case 6:
    q=num/100000;
    r=num%100000;
    ltr = n.twonum(q);
    Str = Str+ltr+n.digit[3];
    num = r;
    break;
    case 5:
    case 4:
    q=num/1000;
    r=num%1000;
    ltr = n.twonum(q);
    Str= Str+ltr+n.digit[2];
    num = r;
    break;
    case 3:
    if (len == 3)
    r = num;
    ltr = n.threenum(r);
    Str = Str + ltr;
    num = 0;
    break;
    case 2:
    ltr = n.twonum(num);
    Str = Str + ltr;
    num=0;
    break;
    case 1:
    Str = Str + n.unitdo[num];
    num=0;
    break;
    default:
    num=0;
    System.out.println("Exceeding Crore....No conversion");
    System.exit(1);
    }
    if (num==0)
    System.out.println(Str+" ");
    }
    }
    catch(Exception e)
    {
    System.out.print(e);
    }
    }
    }
    
    op
  • vinci

    vinci

    @vinci-e4PtMU Jan 15, 2012

    hmm this one is what i was searching since long.Thanks for the help .you solved my query .