ARTICLEViews: 571Share  Posted by - Anonymous

Given an array of words and a number k, your task is to return an array with length k

Given an array of words and a number k, your task is to return an array with length k where the ith element is the number of unique prefixes with length i + 1 among the given words (including only words that are at most i characters long).



function solution(words, k) {

  const rtnArr = new Array(k);

  const prfArr = [];

   

  for(let i = 0; i < k; i++){

    const prArr = words.map(item => item.length >= i+1 ? item.substring(0, i+1) : "");

    const uniqueArr = prArr.filter((value, index, self) => {

    return value && self.indexOf(value) === index;

  });

    rtnArr[i] = uniqueArr.length;

  }

  return rtnArr;

}


Given an array of integers and a size k, Reverse every sub-array of k group elements. In this tutorial, I have explained a java code ...

Find Pairs in Array with Given Sum | Programming Tutorials

Find Kth Largest/Smallest Element in an Array | PriorityQueue in Java &amp; C++ | DSA-One Course #33

Find missing number in an array

Kth largest element in an array | Kth smallest element in an array



Views -