Skip to content

DSA - 20th june Task #25

Description

@mohhdasif786

DSA Task 1 - Reverse Prefix Sum

Given:

l = [1, 2, 4, 5, 7, 8]

Prefix Sum Example:

n = 0
ll = []

for i in range(len(l)):
    n += l[i]
    ll.append(n)

print(ll)

Output:

[1, 3, 7, 12, 19, 27]

Task

Find the Reverse Prefix Sum.

For each index, calculate:

sum of current element + all elements to its right

Example

Input:

[1, 2, 4, 5, 7, 8]

Output:

[27, 26, 24, 20, 15, 8]

Hint

27 = 1+2+4+5+7+8
26 = 2+4+5+7+8
24 = 4+5+7+8
...

DSA Task 2 - Frequency Count Without Counter

Given:

l = [1, 2, 3, 4, 5, 5, 1]

Using Counter:

from collections import Counter

print(Counter(l))

Output:

{1: 2, 2: 1, 3: 1, 4: 1, 5: 2}

Task

Find the frequency of each element without using Counter.

Expected Output

{
    1: 2,
    2: 1,
    3: 1,
    4: 1,
    5: 2
}

Rules

  • Do not use Counter
  • Use dictionary only
  • Use loops

Day 15 - Arrays: Basics & Two Pointers

Question 1: Prefix Sum

Given:

arr = [1, 2, 3, 4, 5]

Create a prefix sum array.

Expected Output

[1, 3, 6, 10, 15]

Question 2: Two Pointers

Given a sorted array:

arr = [1, 2, 3, 4, 6, 8]
target = 10

Find if there exists a pair whose sum equals the target.

Expected Output

2 + 8 = 10

Day 16 - Arrays: Medium Patterns

Question 1: Rotate Array Right by K

Given:

arr = [1, 2, 3, 4, 5]
k = 2

Rotate the array to the right by k positions.

Expected Output

[4, 5, 1, 2, 3]

Question 2: Merge Two Sorted Arrays

Given:

arr1 = [1, 3, 5]
arr2 = [2, 4, 6]

Merge them into a single sorted array.

Expected Output

[1, 2, 3, 4, 5, 6]

Day 17 - Strings: Pattern Problems

Question 1: Reverse Words in a String

Given:

s = "I love Python"

Reverse the order of words.

Expected Output

Python love I

Question 2: Check Anagram

Given:

s1 = "listen"
s2 = "silent"

Check whether both strings are anagrams.

Expected Output

Anagram

Day 18 - Strings / Sliding Window

Question 1: Longest Substring Without Repeating Characters

Given:

s = "abcabcbb"

Find the length of the longest substring without repeating characters.

Expected Output

3

Explanation

abc

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions