Yatra.com Interview Question for SDE-2s


Country: India
Interview Type: Phone Interview




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

hjhjh

- Anonymous September 03, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

var dates = [
  '1 Sep 2016 - 10 Sep 2016',
  '1 Jan 2009 - 31 Aug 2015',
]

function generateFn (dates) {
  var times = []
  for (var i = 0; i < dates.length; ++i) {
    var twoDates = dates[i].split(' - ')
    times.push([
      new Date(twoDates[0]).valueOf(),
      new Date(twoDates[1]).valueOf(),
      dates[i],
    ])
  }
  return function (date) {
    var time = new Date(date).valueOf()
    for (var i = 0; i < times.length; ++i) {
      if (
        time >= times[i][0] &&
        time <= times[i][1]
      ) {
        return times[i][2]
      }
    }
    return null
  }
}

var fn = generateFn(dates)
var date = '12 Jan 2014'
var result = fn(date)

- Anonymous September 04, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import htsjdk.samtools.util.IntervalTree;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Iterator;
import java.util.stream.Stream;

/*
Found an implementation of the interval tree (Samtools.github.io//htsjdk/) instead of implementing it!

Insert date intervals into an interval tree. Each date could be converted to a long or int
denoting number of days from the Epoch ( to simplify the problem).
You can query for the list of all intervals into which a particular day can drop using
the tree. You query with an interval where the lower range (day) and the upper range (day) are
the same.
 */

public class App {
    public static void main(String[] args) {

        final IntervalTree <String> tree = new IntervalTree<>();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");

        String [] [] dateIntervals = {
            {"09/01/2016", "09/10/2016"},
                {"09/11/2016", "09/13/2016"},
                {"09/14/2016", "09/22/2016"},
                {"09/15/2016", "09/16/2016"},
                {"10/01/2016", "10/10/2016"},
                {"10/11/2016", "10/12/2016"},
                {"10/13/2016", "10/14/2016"},
                {"10/15/2016", "10/16/2016"},
                {"10/01/2016", "10/01/2017"},
                {"10/02/2017", "10/12/2017"},
                {"10/10/2016", "10/13/2016"},
                {"10/10/2016", "10/15/2016"},
                {"10/10/2016", "10/16/2016"},
                {"10/10/2016", "10/18/2016"},
        };
        Stream.of(dateIntervals).forEach (r -> {
            int dateLow = (int) LocalDate.parse(r[0], formatter).toEpochDay();
            System.out.println(dateLow
            );
            int dateHigh = (int) LocalDate.parse(r[1], formatter).toEpochDay();
            System.out.println(dateHigh);
            System.out.println(dateLow + " " +  dateHigh  +" " + r[0]+ "~"+ r[1]);
            tree.put (dateLow, dateHigh, r[0]+ "~"+ r[1]);
        });

       Iterator<IntervalTree.Node<String>> query = tree.overlappers(17085, 17085 );
       while (query.hasNext()) {
           System.out.println(query.next());
       }
    }

}

- Makarand September 09, 2017 | 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