Interview Question


Country: India




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

create and array of structure of Months of size 30.
parse the table, according to product & month update corresponding entry

after complete parsing, print the result for all non-zero entries from 1st product to 30th product.

Make sure to keep entry in lexicographic order

- SK January 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

plzz write program , bcz i cud not ...........

- aryan January 17, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use LinkedHashMap<String, int[]> to store data in java.

public static void getProdCount(String[][] input){
        LinkedHashMap<String, int[]> map = new  LinkedHashMap<String, int[]>();
        for(int i=0;i<input.length;i++){
            int[] list= map.get(input[i][0]);
            if(list==null){
                list = new int[12];

            }
            String date = input[i][1];   //2/1/1980
            int index = Integer.parseInt(date.split("/")[0])-1;
            list[index] = list[index]+1;
            map.put(input[i][0],list);
        }

        for(Map.Entry<String, int[]> entry:map.entrySet()){
            int[] list = entry.getValue();
            for(int i=0;i<list.length;i++){
                if(list[i]>0)
                    System.out.println(entry.getKey()+"    "+getMonth(i) +"   "+list[i]);
            }
        }
    }

    public static String getMonth(int i){
        String[] month = {"Jan","Feb","March","April","May","June","July","Aug","Sep","Oct","Nov","Dec"};
        return month[i];
    }

pass input as :
String[][] input = {
{"A","1/1/1980"},
{"B","1/1/1980"},
{"C","1/1/1980"},
{"A","1/1/1980"},
{"B","1/1/1980"},
{"C","2/1/1980"},
{"A","7/1/1980"},
{"B","1/1/1980"},
{"C","5/1/1980"},
{"A","3/1/1980"},
{"B","1/1/1980"},
{"C","2/1/1980"}};

- YL January 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Program
    {
        static void Main(string[] args)
        {
            List<Sales> x = new List<Sales>();

            x.Add(new Sales{productName="A",date=DateTime.Parse("1/1/1980")});
              x.Add(new Sales{productName="B",date=DateTime.Parse("2/1/1980")});
              x.Add(new Sales{productName="A",date=DateTime.Parse("1/2/1980")});

              x.Add(new Sales{productName="C",date=DateTime.Parse("1/1/1980")});

            var t  = from z in x group z by new {m=z.date.ToString("MMMM"),z.productName} into temp   select new {ProductName =temp.Key.productName ,Month =temp.Key.m,Copies =temp.Count()} ;

            foreach (var x1 in t)
            {
                Console.WriteLine(x1.ProductName+ " "+x1.Month+ " "+x1.Copies);
            }

            }

        public class Sales
        {
            public string productName;
            public DateTime date;
        }
    }

- raushan08bce253 January 18, 2014 | 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