Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Maximize K Corner Sum
00:00
5 left

Maximize K Corner Sum

MediumPython

Problem

Maximize sum of K corner elements in Array.

Given an integer array nums and integer k, select exactly k elements, where each selected element must come from either the left or right end of the array. Return the maximum possible sum.

Function signature: max_sum_k_corner_elements(nums, k) Input is a list of integers and an integer. Output is an integer.

Example: nums = [1, 2, 3, 4, 5, 6, 1], k = 3 returns 12, by selecting 5, 6, 1 from the right corner.

Constraints: 1 <= k <= len(nums) <= 1000; values may be negative.

Constraints

  • 1 <= k <= len(nums) <= 1000
  • -10^9 <= nums[i] <= 10^9
  • Exactly k elements must be selected
  • Selected elements must come from the two ends of the array

Function Signature

def max_sum_k_corner_elements(nums, k):
Interviewer

Your question is Maximize K Corner Sum. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.