SOLID principles in swift

SOLID represents 5 five design principles intended to make object-oriented designs more understandable, flexible, and maintainable.  Let’s discuss one by one 1. Single Responsibility Principle Every class should have only one responsibilityExample: In below example class UserProfileManager is single resposnsebility class which has getUserProfile function 2.Open/Closed Principle Software entities such as classes, modules, and functions should be open for …

SOLID principles in swift Read More »

How to generate parentheses

[Question]: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.Example: – n = 2. —   [“(())”, “()()”] Approach: We can solve using backtracking / recursion

How to Remove all occurrence of certain number ?

[Question]: Given an integer array nums and an integer k, remove all occurrences of k in nums in-place. The order of the elements may be changed. Then return the count after removal Approach: We can declare a variable which holds index initial it’s 0 now move elements which are not matched with k

How to rotate linked list with K-th places ?

[Question]: Given the head of a linked list, rotate the list to the right by k places.Example: – Input: head = [1,2,3,4,5], k = 2 Output: [4,5,1,2,3] #Approach Step: 1 Create tail node which moves till endsStep: 2 Create curr the tail node is the (len-k)-th node (1st node is head)Step: 3 Reorder linked list