# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="eNLQI5OfZtWD"
# # Code Signal Diving Deeper

# + [markdown] id="0mIu_4dBZ4QQ"
# ## Extract Eack Kth (34)
# Given array of integers, remove each kth element from it.
#
# ### Example
#
# For inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and k = 3, the output should be
# solution(inputArray, k) = [1, 2, 4, 5, 7, 8, 10].
#
#

# + id="b_7SnT7fZ4uo"
def extractEachKth(inputArray, k):
    loop = ((len(inputArray) - (len(inputArray)%k))/k)
    loop = int(loop)
    L = []
    for i in range(loop):
        L.insert(0,i+1)
    for i in L:
        del inputArray[(i*k)-1]
    return inputArray


# + [markdown] id="F-SJHz0vZ6io"
# ## First Digit (35)
# Find the leftmost digit that occurs in a given string.
#
# ### Example
#
# For inputString = "var_1__Int", the output should be
# solution(inputString) = '1';
# For inputString = "q2q-q", the output should be
# solution(inputString) = '2';
# For inputString = "0ss", the output should be
# solution(inputString) = '0'.

# + id="tTdIOykFZ63F"
def firstDigit(inputString):
    #output the first digit found in a string
    L = list(inputString)
    J = []
    for i in L:
        if i.isnumeric():
            J.append(i)
    return J[0]


# + [markdown] id="lraKkzAKZ7bU"
# ## Different Symbols Naive (36)
# Given a string, find the number of different characters in it.
#
# ### Example
#
# For s = "cabca", the output should be
# solution(s) = 3.
#
# There are 3 different characters a, b and c.

# + id="-kFsq-idZ7w0"
from collections import Counter
def differentSymbolsNaive(s):
    ## Given a string, find the number of different characters in it.
    c = Counter(s)
    getList(c)
    return len(c)
    
def getList(dict):
    ## Create a list of all the keys in a given dictionary
    ## For example getList(Dictionary["SubDictionary"])
    ## Or getList(Dictionary)
    list = []
    for key in dict.keys():
        list.append(key)
          
    return list


# + [markdown] id="h06E5sc1Z85S"
# ## Array Max Consecutive Sum (37)
# Given array of integers, find the maximal possible sum of some of its k consecutive elements.
#
# ### Example
#
# For inputArray = [2, 3, 5, 1, 6] and k = 2, the output should be
# solution(inputArray, k) = 8.
# All possible sums of 2 consecutive elements are:
#
# 2 + 3 = 5;
# 3 + 5 = 8;
# 5 + 1 = 6;
# 1 + 6 = 7.
# Thus, the answer is 8.

# + id="OLFSwxBfZ9Po"
def arrayMaxConsecutiveSum(inputArray, k):
    ## Given array of integers, find the maximal possible sum of some of its k consecutive elements.
    S = sum(inputArray[:k])
    M = S
    for i in range(len(inputArray) - k):
        S += ( inputArray[i+k] - inputArray[i])
        if M < S:
            M = S
    return M

StarcoderdataJupyterScriptsDedupFiltered