Skip to content

Instantly share code, notes, and snippets.

@ahmed1hsn
Last active September 2, 2025 12:52
Show Gist options
  • Select an option

  • Save ahmed1hsn/e28fdb26a7375c887afa22160508f3af to your computer and use it in GitHub Desktop.

Select an option

Save ahmed1hsn/e28fdb26a7375c887afa22160508f3af to your computer and use it in GitHub Desktop.
Interview Question
const fruits = ["Apple", "Mango", "Orange", "Banana", "Kiwi"]
const characters = [ "b", "c"]
// Problem: find Longest fruit name which doens't contain any of thse characters.
// Fruit Element Length
// Character inclusion in Fruit Element.
let fruitWithHighestLength = "";
for (const fruitElement of fruits) {
// console.log(fruitElement);
let fruitIncludesAnyCharacter = false;
const fruitElementLengthGreater = fruitElement.length > fruitWithHighestLength?.length
if (fruitElementLengthGreater) {
for (const characterElement of characters) {
// console.log(characterElement);
if (fruitElement.toLocaleLowerCase().includes(characterElement)) {
fruitIncludesAnyCharacter = true
}
}
}
if (fruitElementLengthGreater && !fruitIncludesAnyCharacter) {
// console.log(fruitElement)
fruitWithHighestLength = fruitElement
}
}
console.log("fruitWithHighestLength:", fruitWithHighestLength)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment