-1

My problem is to create suffix array for a given string.
So far I've taken the tails of the string paired them with indexes and sorted them by strings.
I need to drop the string part of the tuple so I can return Seq[Int], but I don't know how to do that.

This is what I tried to do:

def suffixArray(s: String): Seq[Int] = s.tails.zipWithIndex.toSeq.sortBy(_._1)
Andronicus
  • 25,419
  • 17
  • 47
  • 88
turjake
  • 3
  • 3

2 Answers2

2

You can simply map it:

seq.map(_._2)

or using pattern matching:

seq.map { case(s, i) -> i }
Andronicus
  • 25,419
  • 17
  • 47
  • 88
1

try

def suffixArray(s: String): Seq[Int] = s.tails.zipWithIndex.toSeq.sortBy(_._1).map(_._2)
QuickSilver
  • 3,915
  • 2
  • 13
  • 29