Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8875403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:58:02+00:00 2026-06-14T18:58:02+00:00

I have an array: Array[[List[Int]]](81) ( this is a val ) I want to

  • 0

I have an array: Array[[List[Int]]](81) ( this is a val )

I want to break it down say row-wise and if any of the elements in that particular row has only one element in the list, say b.size = 1, then I want to remove that element in ‘b’, from every other list in that particular row of the Array.

I’m not sure, how to go about considering just the first 9 elements, then the next 9 elements from the Array, given the constraint that I don’t use mutable variables. ( so just vals and not vars ).

So far:
I have a function that accepts the list and the element to be removed from it.
But, how do I go about iterating through every row in the above array or every column in the array, and go back to the starting of the row, if I find a list with just one element, to update the other elements in the list, is my question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:58:03+00:00Added an answer on June 14, 2026 at 6:58 pm

    Assuming you mean you have an Array[Array[List[Int]]], this sounds like it’ll do what you’re after:

    scala> def filterRow(arr:Array[List[Int]]):Array[List[Int]] = {
         |   val found:Option[Int] = arr.collectFirst{case List(x) => x};
         |   found.map(f =>
         |     arr.map(l =>
         |       if (l.size == 1) l else l.filterNot(_ == f)
         |     )
         |   ).getOrElse(arr)
         | }
    filterRow: (arr: Array[List[Int]])Array[List[Int]]
    scala> val a = Array(Array(List(1),List(1,2),List(1,2,3)),Array(List(2),List(1,2),List(1,2,3)))
    a: Array[Array[List[Int]]] = Array(Array(List(1), List(1, 2), List(1, 2, 3)), Array(List(2), List(1, 2), List(1, 2, 3)))
    scala> a.map(filterRow)
    res0: Array[Array[List[Int]]] = Array(Array(List(1), List(2), List(2, 3)), Array(List(2), List(1), List(1, 3)))
    

    If not, hopefully it gives you enough of a lead to work it out. Otherwise, you might need to clarify your question a bit more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two-dimension array List<List<int>> boardArray How can I enumerate throw this array to
Closed as exact duplicate of this question . I have an array/list of elements.
I have an array list of objects and I am using this example to
I have an array containing a list of files. I want to sort it
I have a collection (or list or array list) in which I want to
I have an array list ArrayList<String> firstname; In this I am storing n number
i have an array list of type String[]. i want to order it by
Possible Duplicate: How to convert List<Integer> to int[] in Java? I have an ArrayList
I have the following code: List<int> intList = new ArrayList<int>(); for (int index =
Possible Duplicate: list.clear() vs list = new ArrayList<int>(); I have a list: List<Integer> l1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.