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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:18:19+00:00 2026-05-22T12:18:19+00:00

Suppose I am given number of lines segments in Cartesian coordinate system.Each line is

  • 0

Suppose I am given number of lines segments in Cartesian coordinate system.Each line is given as [x0,y0] and [x1,y1].Algorithm should find a perpendicular that cross maximum number of lines.
In this example it crosses four lines:

enter image description here

What algorithm can do it with minimum complexity?(i would prefer c++ but some kind of pseudo code is OK too)

P.S The point to think about is when several lines start/end in the same x coordinate

Thank you.

  • 1 1 Answer
  • 1 View
  • 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-05-22T12:18:20+00:00Added an answer on May 22, 2026 at 12:18 pm
    1. Convert each line to a interval of [x_start,x_end] for each segment.
    2. Create a datastructure that contains a flag for whether it is a start or end point, as well as the point value.
    3. Sort all the points and then iterate through them incrementing a counter when you hit a start point and decrementing a counter when you hit an end point. Keep track of the maximum value.
    4. Repeat with the Y values if desired.

    O(n lg n) time complexity

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

Sidebar

Related Questions

i am given a a text file with 8 lines, and on each line
Suppose that my Haskell function is given an input, which is supposed to be
Let E be a given directed edge set. Suppose it is known that the
Given connected line segments A->B->C->D (A->B is a line segment, then B->C is another
I have this code: File.foreach(testfile.txt) { |line| print line } lines = File.readlines(testfile.txt) lines.each
Suppose we are given a set of closed intervals where each interval is in
Suppose I'm given a large dictionary in flat file with 200 million words and
Suppose I was given a URL. It might already have GET parameters (e.g. http://example.com/search?q=question
I have recently come across an interesting question on strings. Suppose you are given
/one_path/some_page.php?var1=value1&var2=value2&var3=value3 Suppose I'm given something like the above. Not just the query variable string,

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.