diff --git a/README.md b/README.md index 9809a8ea..05f67b1a 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Read [CONTRIBUTING.md](./CONTRIBUTING.md) for contribution guidelines. 21. [Day 21 -- Pair Sum N and Max Subarray Sum](./day21) -- [http://codetoexpress.tech/dc/day21/](http://codetoexpress.tech/dc/day21/) 22. [Day 22 -- Common Elements Search](./day22) -- [http://codetoexpress.tech/dc/day22/](http://codetoexpress.tech/dc/day22/) 23. [Day 23 -- Combination Sum](./day23) -- [http://codetoexpress.tech/dc/day23/](http://codetoexpress.tech/dc/day23/) +24. [Day 24 -- Array Circular Rotation](./day24) -- [http://codetoexpress.tech/dc/day24/](http://codetoexpress.tech/dc/day24/) ## [More Problems](./BONUS/README.md) diff --git a/day24/Daily Codes.png b/day24/Daily Codes.png new file mode 100644 index 00000000..2b5372ce Binary files /dev/null and b/day24/Daily Codes.png differ diff --git a/day24/JavaScript/isRotation_madhav.js b/day24/JavaScript/isRotation_madhav.js new file mode 100644 index 00000000..013a4927 --- /dev/null +++ b/day24/JavaScript/isRotation_madhav.js @@ -0,0 +1,34 @@ +/** + * @author MadhavBahlMD + * @date 22/01/2019 + * Method - Circular Search -- Time = O(n) + */ + +function isRotation (arr1, arr2) { + let len1 = arr1.length, + len2 = arr2.length; + + // return false if lengths are different + if (len1 !== len2) return false; + + // find position of first element of array2 in array 2 + let isRotated = true, + pos = arr1.indexOf (arr2[0]); + + // Return false if element not found + if (pos < 0) return false; + + // Check all the other numbers + for (let i=0; i