Professional Documents
Culture Documents
Experiment 1.2
Student Name: Aaditya Narain Singh UID: 21BCS3653
Branch: BE-CSE Section/Group: CC-649(A)
Semester: VI Date of Performance: 17/01/24
Subject Name: AP Lab Subject Code: 21CSP-351
2. OBJECTIVE:
The experiment aims to equip skills to write reliable, compact, and efficient
code quickly, emphasizing logic-building capabilities to tackle complex
problems using different approaches and work with linear data structures.
3. APPROACH/CODE:
a) Rotate String
Given two strings s and goal, return true if and only if s
can become goal after some number of shifts on s.
A shift on s consists of moving the leftmost character of s to the rightmost
position.
For example, if s = "abcde", then it will be "bcdea" after one shift
};
OUTPUT:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
b) CODE:
/**
* @param {string} haystack
* @param {string} needle
* @return {number}
*/
var strStr = function(haystack, needle) {
let index = haystack.indexOf(needle);
return index;
};
OUTPUT:
DEPARTMENT OF
4.TIME COMPLEXITY:
(A) O(N)
(B) O(N)
5.LEARNING OUTCOMES:
Deal with Strings more proficiently.
Being able to solve simple String problems presented using
different approaches .
Make an optimised code