Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.






                /*Google Interview Question for Front-end Software Engineers - you are on a biz trip and travelling from one city to another. you have a stack of unsorted flight boarding passes. only departure city and destination city are on the boarding pass. how do you find the first departure city and your final destination city, write the solution in javascript.*/

/*Key solution strategy - First note, that each city will be shown up in the boarding ticket 2 times (one for departure and one for arrival) - Except the first city (being the first departure) and the last city (being the last arrival) which will show up only once. 
So arithmatically all cities will cancel each other, except the first departure and final arrival city.

A)  Store the cities in a hashmap.

B) We're going to map each city to the net in and out number ( -1 or +1 ). Then traverse through the hashmap.
For departure, decrease value of net in and out, for arrival, increase value of net in and out. 

C) If a departure-city has not been stored yet in the hashmap, meaning this city has not been travelled yet, So store it with a value of -1

Else, being a departure-city decrement its value by 1

D) If an arrival-city has not been stored yet in the hashmap, meaning this city has not been travelled yet, So store it with a value of 1

Else, being an arrival city, increment its value by 1.

E) So, when the Hashmap is fully constructed, the value of cities will cancel each other, except the First arrival and final destination.

 So, scan through the final hash table to find +1, which is the destination, and -1, which is the departure.

var map = {
	tkt1: {
		departure: 'Los Angeles',
		arrival: 'San Francisco'
	tkt2: {
		departure: 'San Francisco',
		arrival: 'New York'
	tkt3: {
		departure: 'Moscow',
		arrival: 'Mali'
	tkt4: {
		departure: 'Barcelona',
		arrival: 'Moscow'
	tkt5: {
		departure: 'New York',
		arrival: 'Barcelona'

findDepartureArrival = function(map) {
	var hashMap = {};

	for (var tkt in map) {
		var depart = map[tkt].departure;
		var arriv = map[tkt].arrival;

		if (!(depart in hashMap))
			hashMap[depart] = -1;
			hashMap[depart] = hashMap[depart] - 1;

		if (!(arriv in hashMap))
			hashMap[arriv] = 1;
			hashMap[arriv] = hashMap[arriv] + 1;
	return hashMap;

{ 'Los Angeles': -1,
  'San Francisco': 0,
  'New York': 0,
  Moscow: 0,
  Mali: 1,
  Barcelona: 0 }*/