Attempt 1 ✅

/**
 
* @param {string[][]} paths
 
* @return {string}
 
*/
 
var destCity = function(paths) {
 
/**
 
this is easy with double pass, put everything in dictionary and then check which value didn't occur twice, to handle in single page with city as key, store an object as value which is store frequency and position, position 0 if the element was first and 1 if the element was second
 
is my approach correct?
 
no, here set has to be used.
 
How? set is another option, I'm not sure.
 
Single pass is difficult, doing with double pass for now.
 
Tried single pass by comparing secondEl and checking in dict the value as 1, that didn't work.
 
*/
 
let dict = {};
 
let result = -1;
 
for(let i = 0; i < paths.length; i++) {
 
let curPath = paths[i];
 
let firstEl = curPath[0];
 
let secondEl = curPath[1];
 
  
 
if (dict[firstEl]) {
 
delete dict[firstEl];
 
} else {
 
dict[firstEl] = 1;
 
}
 
  
 
if (dict[secondEl]) {
 
delete dict[secondEl];
 
} else {
 
dict[secondEl] = 1;
 
}
 
}
 
  
 
for(let i = 0; i < paths.length; i++) {
 
let curPath = paths[i];
 
let secondEl = curPath[1];
 
if (dict[secondEl]) {
 
result = secondEl;
 
break;
 
}
 
}
 
  
 
return result;
 
};