I have an ArrayList of ArrayLists. I want to make sure that each of the constituent ArrayLists has the same number of items. Is there any way to do this in less than n! time?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Absolutely! Iterate over the
ArrayLists one at a time. Store the size of the firstArrayList, then confirm that the sizes of all the otherArrayLists match the size of the first list. Total time required is O(n), where n is the number of lists.For example:
Hope this helps!