Skip to main content

This module is for TwoSum operations and subsequence checks

Project description

TwoSum Library

A simple Python library to find indices of numbers that sum up to a target in sorted arrays and check for subsequences.

Functions

1. twoSumK(numbers: List[int], target: int) -> List[int]

Description:
This function takes a sorted list of integers and a target integer. It returns the 1-based indices of the two numbers that add up to the target.

Parameters:

  • numbers (List[int]): A sorted list of integers.
  • target (int): The target sum.

Returns:

  • List[int]: A list containing the 1-based indices of the two numbers that sum to the target. Returns an empty list if no such numbers exist.

Example:

result = twoSumK([2, 7, 11, 15], 9)  # Output: [1, 2]

2. twoSum(numbers: List[int], target: int) -> List[int]

Description:
This function operates similarly to twoSumK, but it returns 0-based indices.

Parameters:

  • numbers (List[int]): A sorted list of integers.
  • target (int): The target sum.

Returns:

  • List[int]: A list containing the 0-based indices of the two numbers that sum to the target. Returns an empty list if no such numbers exist.

Example:

result = twoSum([2, 7, 11, 15], 9)  # Output: [0, 1]

3. is_subsequence(s: str, t: str) -> bool

Description:
This function checks if string s is a subsequence of string t.

Parameters:

  • s (str): The string to check as a subsequence.
  • t (str): The string in which to check for the subsequence.

Returns:

  • bool: Returns True if s is a subsequence of t, otherwise False.

Example:

result = is_subsequence("abc", "ahbgdc")  # Output: True

Installation

To use this library, you can clone the repository or install it via pip (if published):

pip install your_library_name

Usage

Import the functions into your script as follows:

from your_library_name import twoSumK, twoSum, is_subsequence

# Example usage
indices = twoSumK([2, 3, 4], 6)
print(indices)  # Output: [1, 3]

License

This project is licensed under the MIT License - see the LICENSE file for details.


Feel free to modify any sections to better fit your library or personal style!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tamilan-0.1.1.tar.gz (2.5 kB view hashes)

Uploaded Source

Built Distribution

tamilan-0.1.1-py3-none-any.whl (2.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page