Advertisement
samimwebdev

Problem Solving Exercise-Sliding Window

Dec 21st, 2022
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. 1.Frequency Counter - sameFrequency
  2. Write a function called sameFrequency. Given two positive integers, find out if the two numbers have the same frequency of digits.
  3.  
  4. Your solution MUST have the following complexities:
  5. Time: O(N)
  6.  
  7. Sample Input:
  8.  
  9. sameFrequency(182,281) // true
  10. sameFrequency(34,14) // false
  11. sameFrequency(3589578, 5879385) // true
  12. sameFrequency(22,222) // false
  13.  
  14. 219. Contains Duplicate II
  15. https://leetcode.com/problems/contains-duplicate-ii/
  16. Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k.
  17. Example 1:
  18.  
  19. Input: nums = [1,2,3,1], k = 3
  20. Output: true
  21. Example 2:
  22.  
  23. Input: nums = [1,0,1,1], k = 1
  24. Output: true
  25. Example 3:
  26.  
  27. Input: nums = [1,2,3,1,2,3], k = 2
  28. Output: false
  29.  
  30. 442. Find All Duplicates in an Array
  31. https://leetcode.com/problems/find-all-duplicates-in-an-array/
  32. Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice.
  33.  
  34. You must write an algorithm that runs in O(n) time and uses only constant extra space.
  35.  
  36. Example 1:
  37.  
  38. Input: nums = [4,3,2,7,8,2,3,1]
  39. Output: [2,3]
  40. Example 2:
  41.  
  42. Input: nums = [1,1,2]
  43. Output: [1]
  44. Example 3:
  45.  
  46. Input: nums = [1]
  47. Output: []
  48.  
  49.  
  50. 217. Contains Duplicate
  51. https://leetcode.com/problems/contains-duplicate/
  52. Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
  53. Example 1:
  54.  
  55. Input: nums = [1,2,3,1]
  56. Output: true
  57. Example 2:
  58.  
  59. Input: nums = [1,2,3,4]
  60. Output: false
  61. Example 3:
  62.  
  63. Input: nums = [1,1,1,3,3,4,3,2,4,2]
  64. Output: true
  65.  
  66. 387. First Unique Character in a String
  67. https://leetcode.com/problems/first-unique-character-in-a-string/
  68.  
  69. Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.
  70.  
  71. Example 1:
  72.  
  73. Input: s = "leetcode"
  74. Output: 0
  75. Example 2:
  76.  
  77. Input: s = "loveleetcode"
  78. Output: 2
  79. Example 3:
  80.  
  81. Input: s = "aabb"
  82. Output: -1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement