Your getCount() method is a little difficult to read, on one long line like that, and way too complicated. s.count(_ == 'a') is both concise and efficient.
It's not clear why the number of s repetitions possible in n is called duplicate. It seems an odd choice for that variable name.
Your algorithm is sound, I just find it excessively verbose, especially ...
(Disclamer: It's been quite a while that I used Scala.)
Your code is quite complicated. Scala provides the LazyList which allows to virtually repeat the string indefinitely. You then just need to "take" the n first characters, filter out the as and count them:
def repeatedString(s: String, n: Int) =
LazyList.continually(s).flatten.take(n).filter(_ == 'a'...
Your counter is a cumulative sum of elevation changes; elevation would be a more precise name for it.
Ultimately, the goal is to count the number of times the elevation changes from -1 to 0. To do that:
Translate the 'U' and 'D' steps into +1 and -1, respectively.
Obtain a sequence representing the elevation profile of the hike using Seq.scan.
Count the ...
There's nothing wrong with or "not functional" about your approach. This might be opinion territory, but personally I would consider using foldLeft as it might be more readable and you can potentially eliminate some of the complexity of your cases.
(also I got rid of n here as it is completely irrelevant, I know it's a problem from a website so you have to ...
You can use below approach that will help you if you add more rules in future. This will also be generic, you do not required hard code product values (like "A" and "B") in the script.
scala> import org.apache.spark.sql.expressions.Window
scala> val w = Window.partitionBy("product_value").orderBy("...
Is the graphic representation of a data structure an integral part of that data structure (val gString = myGrid.asText) or separate and independent from the data structure (val gString = asText(myGrid))?
I tend to favor the former, but if the Grid API is solid and supplies everything needed for one or more graphic representations, then the latter is ...