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 9148009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:09:12+00:00 2026-06-17T11:09:12+00:00

We have three lists which contain people’s names. All three lists have been sorted

  • 0

We have three lists which contain people’s names.

All three lists have been sorted alphabetically.

Now we need to find at least one name which appear in all three lists.


The algorithm I am thinking is like this:

I get three heads out of three lists.

if the three heads are not equal to each other, then I keep the max
one and get two new heads from the lists from which I just dropped the
heads.

Continue above procedure until I find such an element as described in
the beginning.

Is this algorithm correct?


The problem is that I am not sure how to use ocaml to write the function.

  • 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-17T11:09:14+00:00Added an answer on June 17, 2026 at 11:09 am

    Thomash’s algorithm will do the job with two calls of intersect and creating intermediate lists so it isn’t very efficient.

    Your algorithm is essentially correct. An extra bit is that sometimes you have two heads are equal to max and you should drop only the remaining head.

    Here is the revised algorithm written in OCaml:

    let rec intersect xs ys zs =
        match xs, ys, zs with
        | [], _, _ | _, [], _ | _, _, [] -> None
        | x::xs', y::ys', z::zs' -> 
           if x = y && y = z then Some x
           else 
               let m = max x (max y z) in
               if x = m && y = m then intersect xs ys zs'
               else if x = m && z = m then intersect xs ys' zs
               else if y = m && z = m then intersect xs' ys zs
               else if x = m then intersect xs ys' zs'
               else if y = m then intersect xs' ys zs'
               else intersect xs' ys' zs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three lists namely A , B , C All these lists contain
I have a list of MyObjects which I need to divide into three groups:
I have three lists, I need to move Animal object from list animalSource to
I have the following scenario: Two lists of different Types which happen to contain
Right now I have a viewmodel that contains three lists of inputs; textboxinput, dropdownlistinput,
I have two files which both contain a list of words. Is there an
i have three lists with the same number of elements in each other, i
I have three lists of lists, and I'm trying to write a generator function
I have three lists that I want to convert into one list. When I
I have a MySQL database called People which contains the following schema <id,name,foodchoice1,foodchoice2> .

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.