Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Feature #8: Overlapping Topics

Sumit Rawal answered on May 24, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers


Feature #8: Overlapping Topics

0

import scala.collection.convert.ImplicitConversions.`collection asJava`

import scala.collection.mutable

import scala.collection.mutable.ListBuffer

object Solution {

def to_string(arr: Array[String]): String = {

var str = "["

for (i <- 0 until arr.length) {

str += String.valueOf(arr(i))

if (i + 1 < arr.length) str += ", "

}

str += "]"

str

}

def smallestSequence(listA: Array[String], listB: Array[String]): Array[String] = { // Returns an empty list if one or more list is empty.

if (listA.length == 0 || listB.length == 0) return new Array[String](0)

// We will use this dictionary to keep a count of all unique topics in list b.

val dictListB = new mutable.HashMap[String, Int]()

{

override def default(key: String): Int = 0

}

for (i <- 0 until listB.length) {

val count = dictListB(listB(i))

dictListB.put(listB(i), count + 1)

}

// This will hold the count of number of unique topics in list b.

val countUniqueB = dictListB.size

// uniqueCharacters keeps a count of the number of unique characters of list_b which are present in the current with its required frequency.

var uniqueCharacters = 0

// This dictionary holds the count of all the unique topics in the current window.

val uniqueTopics = new mutable.HashMap[String, Int]() {

override def default(k: String): Int = 0

}

// Checks and appends a topic along with its index from list A in sifted list, if the topic is present in list B.

val siftedListA = new ListBuffer[mutable.HashMap[Int, String]]();

for (i <- 0 until listA.length) {

val str = listA(i)

if (dictListB.contains(str)) {

val tempMap = new mutable.HashMap[Int, String]()

tempMap.put(i, str)

siftedListA.addOne(tempMap)

}

}


Popularity 1/10 Helpfulness 1/10 Language whatever
Source: Grepper
Link to this answer
Share Copy Link
Contributed on May 24 2023
Sumit Rawal
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.