Skip to content

Find Max Subarray Sum from Character Array Input #12

@codewithdhruba01

Description

@codewithdhruba01

“For a given array ‘X’ consisting of non-negative integer characters, find the contiguous subarray with the maximum sum.”

Write a Python program that takes an array X consisting of non-negative integer characters (e.g. ['1', '3', '2']) and finds the contiguous subarray with the maximum sum.

Note: You’ll need to convert characters to integers before processing.
This is a variation of the classic Kadane’s Algorithm problem, but with character input.


Requirements:

  • Convert the character array (e.g. ['1', '2', '3']) into an integer array.
  • Use Kadane’s Algorithm or a similar efficient method to find the maximum sum of a contiguous subarray.
  • Print the maximum sum.
  • Comment your code for better understanding.

Example / Test Cases:

# Test Case 1:
# Input: ['2', '4', '1', '3']
# Converted Input: [2, 4, 1, 3]
# Output: Maximum subarray sum = 10

# Test Case 2:
# Input: ['5', '0', '2', '1']
# Converted Input: [5, 0, 2, 1]
# Output: Maximum subarray sum = 8

# Test Case 3:
# Input: ['1', '0', '0', '1']
# Output: Maximum subarray sum = 2

# Test Case 4:
# Input: ['0', '0', '0']
# Output: Maximum subarray sum = 0

📌 Acceptance Criteria:

  • Code must be in Python.
  • Step : Go to Interview-Questions Folder : then Create a File: max-subarray-char-input.py
  • Include sample input/output in comments.
  • Follow clean naming conventions and Python formatting guidelines.

🛠️ How to Work on This Issue:

  1. Comment on this issue to get it assigned.

  2. Once assigned, create a new branch from the main branch:

    git checkout -b feature/max-subarray-char-input
  3. Write your code, test it thoroughly.

  4. Commit your changes:

    git commit -m "Add Python program to find max subarray sum from char array input"
  5. Push your branch to GitHub:

    git push origin feature/max-subarray-char-input

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomershelp wantedExtra attention is neededquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions