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

  • Home
  • SEARCH
  • 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 7749779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:07:27+00:00 2026-06-01T11:07:27+00:00

This is an Amazon interview Question.I have solved this problem in O(n) using dynamic

  • 0

This is an Amazon interview Question.I have solved this problem in O(n) using dynamic
programming.But I want to know can there be more optimization than O(n)

for e.g. suppose below is the array

3 7 1 4 2 4 returns 4

5 4 3 2 1 returns Nothing

4 3 2 2 3 returns 1

This is the code i have written Code

  • 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-01T11:07:28+00:00Added an answer on June 1, 2026 at 11:07 am

    Lets say you’ve got int A[N].

    int res = -1;
    int min_value = A[0];
    for(int i=1; i<N; i++) {
        // A[i] - A[j] is maximal, when A[j] is minimal value from {A[0], A[1],.., A[i-1]}
        res = max(res, A[i] - min_value);
        min_value = min(min_value, A[i]);
    }
    return res;
    

    Complexity O(N).

    You need to examine N elements so O(N) is best what you can get.

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

Sidebar

Related Questions

I need to upload a given image using Amazon S3 I have this PHP:
I got this question in an interview with amazon. I was asked to perform
I know this isn't a direct technical problem but this seems like an ideal
This is a very basic Amazon EC2 question, but I'm stumped so here goes.
This question is generic, but is also related to Amazon Web Services. I am
I am using carrierwave to upload images to amazon s3. This works great on
This is a bit of a long shot, but if anyone can figure it
This might seem like a stupid question I admit. But I'm in a small
I posted this in the Amazon Product Advertising forum but noone is responding, so
Amazon has Customers Who Bought This Item Also Bought. I am wondering and want

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.