0% found this document useful (0 votes)
4 views5 pages

Coding Training Week -4 Tasks (II and III B.tech-CSE, ECE, EEE)

The document outlines tasks for Week #4 of coding classes in the Department of Computer Science & Engineering for the academic year 2024-2025. It includes a series of LeetCode problems focused on strings, such as finding the longest substring without repeating characters, identifying palindromic substrings, and reversing vowels in a string. Each problem is accompanied by examples and expected outputs to guide students in their coding exercises.

Uploaded by

gsc619999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Coding Training Week -4 Tasks (II and III B.tech-CSE, ECE, EEE)

The document outlines tasks for Week #4 of coding classes in the Department of Computer Science & Engineering for the academic year 2024-2025. It includes a series of LeetCode problems focused on strings, such as finding the longest substring without repeating characters, identifying palindromic substrings, and reversing vowels in a string. Each problem is accompanied by examples and expected outputs to guide students in their coding exercises.

Uploaded by

gsc619999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Department of Computer Science & Engineering

----------------------------------------------------------------------------------------------------------------

Coding Classes - Week # 4 Tasks

Academic Year: 2024-2025 Year & Semester: II & III B. Tech, IInd Sem

Branch: CSE/ECE/EEE Topic: LeetCode Problems on


Strings - 1

1. Longest Substring Without Repeating Characters

Given a string s, find the length of the longest substring without repeating characters.

Example 1:
Input: s = "abcabcbb"
Output: 3

Explanation: The answer is "abc", with the length of 3.

Example 2:
Input: s = "bbbbb"
Output: 1

Explanation: The answer is "b", with the length of 1.

Example 3:
Input: s = "pwwkew"
Output: 3

Explanation: The answer is "wke", with the length of 3.


Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.

2. Longest Palindromic Substring

Given a string s, return the longest palindromic substring in s.

Example 1:
Input: s = "babad"
Output: "bab"

Explanation: "aba" is also a valid answer.

Example 2:
Input: s = "cbbd"
Output: "bb"
3. Remove Duplicate Letters

Given a string s, remove duplicate letters so that every letter appears once and only once. You
must make sure your result is the smallest in lexicographical order among all possible
results.

Example 1:
Input: s = "bcabc"
Output: "abc"

Example 2:
Input: s = "cbacdcbc"
Output: "acdb"

4. Palindrome Pairs

You are given a 0-indexed array of unique strings words.

A palindrome pair is a pair of integers (i, j) such that:

 0 <= i, j < words.length,


 i != j, and
 words[i] + words[j] (the concatenation of the two strings) is a palindrome
.
Return an array of all the palindrome pairs of words.

You must write an algorithm with O(sum of words[i].length) runtime complexity.

Example 1:

Input: words = ["abcd","dcba","lls","s","sssll"]


Output: [[0,1],[1,0],[3,2],[2,4]]

Explanation: The palindromes are ["abcddcba","dcbaabcd","slls","llssssll"]

Example 2:

Input: words = ["bat","tab","cat"]


Output: [[0,1],[1,0]]

Explanation: The palindromes are ["battab","tabbat"]

Example 3:

Input: words = ["a",""]


Output: [[0,1],[1,0]]

Explanation: The palindromes are ["a","a"]


5. Reverse Vowels of a String

Given a string s, reverse only all the vowels in the string and return it.
The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more
than once.

Example 1:
Input: s = "IceCreAm"
Output: "AceCreIm"

Explanation:
The vowels in s are ['I', 'e', 'e', 'A']. On reversing the vowels, s becomes "AceCreIm".

Example 2:
Input: s = "leetcode"
Output: "leotcede"

6. Repeated Substring Pattern

Given a string s, check if it can be constructed by taking a substring of it and appending


multiple copies of the substring together.

Example 1:
Input: s = "abab"
Output: true

Explanation: It is the substring "ab" twice.

Example 2:
Input: s = "aba"
Output: false

Example 3:
Input: s = "abcabcabcabc"
Output: true

Explanation: It is the substring "abc" four times or the substring "abcabc" twice.

7. Detect Capital

We define the usage of capitals in a word to be right when one of the following cases holds:
 All letters in this word are capitals, like "USA".
 All letters in this word are not capitals, like "leetcode".
 Only the first letter in this word is capital, like "Google".
Given a string word, return true if the usage of capitals in it is right.

Example 1:
Input: word = "USA"
Output: true
Example 2:
Input: word = "FlaG"
Output: false

8. Word Pattern

Given a pattern and a string s, find if s follows the same pattern.


Here follow means a full match, such that there is a bijection between a letter in pattern and
a non-empty word in s. Specifically:
 Each letter in pattern maps to exactly one unique word in s.
 Each unique word in s maps to exactly one letter in pattern.
 No two letters map to the same word, and no two words map to the same letter.

Example 1:
Input: pattern = "abba", s = "dog cat cat dog"
Output: true

Explanation:
The bijection can be established as:
 'a' maps to "dog".
 'b' maps to "cat".

Example 2:
Input: pattern = "abba", s = "dog cat cat fish"
Output: false

Example 3:
Input: pattern = "aaaa", s = "dog cat cat dog"
Output: false

9. Letter Combinations of a Phone Number

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that
the number could represent. Return the answer in any order.

A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1
does not map to any letters.
Example 1:

Input: digits = "23"


Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]

Example 2:

Input: digits = ""


Output: []

Example 3:

Input: digits = "2"


Output: ["a","b","c"]

10. Find the Index of the First Occurrence in a String

Given two strings needle and haystack, return the index of the first occurrence
of needle in haystack, or -1 if needle is not part of haystack.

Example 1:
Input: haystack = "sadbutsad", needle = "sad"
Output: 0

Explanation: "sad" occurs at index 0 and 6.


The first occurrence is at index 0, so we return 0.

Example 2:
Input: haystack = "leetcode", needle = "leeto"
Output: -1

Explanation: "leeto" did not occur in "leetcode", so we return -1.

You might also like