Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Scanned with ACE Scanner
Given an array nums with n objects colored red, white, or blue, sort them in-place so that
objects of the same color are adjacent, with the colors in the order red, white, and blue.
We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.
You must solve this problem without using the library's sort function.
Example 1:
Input: nums = [2,0,2,1,1,0]
Output: [0,0,1,1,2,2]
Example 2:
Input: nums = [2,0,1]
Output: [0,1,2]
Constraints:
• n == [Link]
• 1 <= n <= 300
• nums[i] is either 0, 1, or 2.
CODE: -
class Solution {
public void sortColors(int[] nums) {
int red = 0;
int white = 0;
int blue = [Link] - 1;
while (white <= blue) {
if (nums[white] == 0) {
int temp = nums[white];
nums[white] = nums[red];
nums[red] = temp;
red++;
white++;
} else if (nums[white] == 1) {
white++;
} else {
int temp = nums[white];
nums[white] = nums[blue];
nums[blue] = temp;
}
}
}
2 287. Find the Duplicate Number
Given an array of integers nums containing n + 1 integers where each integer is in the
range [1, n] inclusive.
There is only one repeated number in nums, return this repeated number.
You must solve the problem without modifying the array nums and uses only constant extra
space.
Example 1:
Input: nums = [1,3,4,2,2]
Output: 2
Example 2:
Input: nums = [3,1,3,4,2]
Output: 3
Example 3:
Input: nums = [3,3,3,3,3]
Output: 3
Constraints:
• 1 <= n <= 105
• [Link] == n + 1
• 1 <= nums[i] <= n
• All the integers in nums appear only once except for precisely one integer which
appears two or more times.
CODE: -
class Solution {
public int findDuplicate(int[] nums) {
int slow=0,fast=0;
do{
slow=nums[slow];
slow=0;
while(slow!=fast){
slow=nums[slow];
fast=nums[fast];
}
return slow;
}
}
3 283. Move Zeroes
Given an integer array nums, move all 0's to the end of it while maintaining the relative order
Example 1:
Input: nums = [0,1,0,3,12]
Output: [1,3,12,0,0]
Example 2:
Input: nums = [0]
Output: [0]
Constraints:
• 1 <= [Link] <= 104
• -231 <= nums[i] <= 231 – 1
CODE: -
class Solution {
public void moveZeroes(int[] nums) {
int n=[Link];
int count=0;
for(int i=0;i<n;i++){
if(nums[i]!=0)
nums[count++]=nums[i];
}
while(count<n){
nums[count++]=0;
}
}
}
that they add up to target.
You may assume that each input would have exactly one solution, and you may not use
the same element twice.
You can return the answer in any order.
Example 1:
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
Example 2:
Input: nums = [3,2,4], target = 6
Output: [1,2]
Example 3:
Input: nums = [3,3], target = 6
Output: [0,1]
Constraints:
• 2 <= [Link] <= 104
• -109 <= nums[i] <= 109
• -109 <= target <= 109
CODE:-
class Solution {
public int[] twoSum(int[] nums, int target) {
for(int i=0;i<[Link]-1;i++){
for(int j=i+1;j<[Link];j++){
if(nums[i]+nums[j]==target){
return new int[]{i,j};
}
}
}
return new int[]{-1,-1};
}
}
j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.
Notice that the solution set must not contain duplicate triplets.
Example 1:
Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]
Explanation:
nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.
Example 2:
Input: nums = [0,1,1]
Output: []
Explanation: The only possible triplet does not sum up to 0.
Example 3:
Input: nums = [0,0,0]
Output: [[0,0,0]]
Explanation: The only possible triplet sums up to 0.
Constraints:
• 3 <= [Link] <= 3000
• -105 <= nums[i] <= 105
Code: -
class Solution {
public List<List<Integer>> threeSum(int[] nums) {
List<List<Integer>> ans = new ArrayList<>();
[Link](nums);
for (int i = 0; i < [Link] - 2; i++) {
if (i > 0 && nums[i] == nums[i - 1]) {
continue;
}
int j = i + 1;
int k = [Link] - 1;
while (j < k) {
int sum = nums[i] + nums[j] + nums[k];
if (sum == 0) {
[Link]([Link](nums[i], nums[j], nums[k]));
while (j < k && nums[j] == nums[j + 1]) {
j++;
}
while (j < k && nums[k] == nums[k - 1]) {
k--;
}
j++;
k--;
} else if (sum < 0) {
j++;
} else {
k--;
}
return ans;
}
}
6 20. Valid Parentheses
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input
string is valid.
An input string is valid if:
1. Open brackets must be closed by the same type of brackets.
2. Open brackets must be closed in the correct order.
3. Every close bracket has a corresponding open bracket of the same type.
Example 1:
Input: s = "()"
Output: true
Example 2:
Input: s = "()[]{}"
Output: true
Example 3:
Input: s = "(]"
Output: false
Example 4:
Input: s = "([])"
Output: true
Constraints:
• 1 <= [Link] <= 104
• s consists of parentheses only '()[]{}'.
Code: -
class Solution {
public boolean isValid(String s) {
Stack<Character> st=new Stack<>();
for(int i=0;i<[Link]();i++){
if([Link](i)=='('){
[Link](')');
}
}
else if([Link](i)=='{'){
[Link]('}');
}
else if([Link]() || [Link]()!=[Link](i)){
return false;
}
}
return [Link]();
}
}
7 442. Find All Duplicates in an Array
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.
You must write an algorithm that runs in O(n) time and uses only constant auxiliary space,
excluding the space needed to store the output
Output: [2,3]
Example 2:
Input: nums = [1,1,2]
Output: [1]
Example 3:
Input: nums = [1]
Output: []
Constraints:
• n == [Link]
• 1 <= n <= 105
• 1 <= nums[i] <= n
• Each element in nums appears once or twice.
Code: -
class Solution {
public List<Integer> findDuplicates(int[] nums) {
List<Integer> ans = new ArrayList<>();
int n = [Link];
for (int i = 0; i < n; i++) {
int x = [Link](nums[i]);
if (nums[x - 1] < 0) {
[Link](x);
}
nums[x - 1] *= -1;
}
return ans;
}
}
two integers m and n, representing the number of elements in nums1 and nums2 respectively.
Merge nums1 and nums2 into a single array sorted in non-decreasing order.
The final sorted array should not be returned by the function, but instead be stored inside the
array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements
denote the elements that should be merged, and the last n elements are set to 0 and should be
ignored. nums2 has a length of n.
Example 1:
Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
Output: [1,2,2,3,5,6]
Explanation: The arrays we are merging are [1,2,3] and [2,5,6].
The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.
Example 2:
Input: nums1 = [1], m = 1, nums2 = [], n = 0
Output: [1]
Explanation: The arrays we are merging are [1] and [].
The result of the merge is [1].
Example 3:
Input: nums1 = [0], m = 0, nums2 = [1], n = 1
Output: [1]
Explanation: The arrays we are merging are [] and [1].
The result of the merge is [1].
Note that because m = 0, there are no elements in nums1. The 0 is only there to ensure the
merge result can fit in nums1.
Constraints:
• [Link] == m + n
• [Link] == n
• 0 <= m, n <= 200
• 1 <= m + n <= 200
Code: -
class Solution {
public void merge(int[] num1, int m, int[] num2, int n) {
int i=m-1;
int j=n-1;
int k=m+n-1;
while(j>=0){
if(i>=0 && num1[i]>num2[j]){
num1[k]=num1[i];
k--;
i--;
}
else{
num1[k]=num2[j];
}
}
}
}
Given an integer x, return true if x is a palindrome , and false otherwise.
Example 1:
Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.
Example 2:
Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore
it is not a palindrome.
Example 3:
Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
Constraints:
• -231 <= x <= 231 – 1
CODE: -
class Solution {
public boolean isPalindrome(int x) {
int temp=x;
int rev=0;
while(x>0){
int digit=x%10;
rev=(rev*10)+digit;
x=x/10;
}
if (rev==temp) return true;
return false;
}
}
Given a 0-indexed integer array nums, find a peak element, and return its index. If the array
contains multiple peaks, return the index to any of the peaks.
You may imagine that nums[-1] = nums[n] = -∞. In other words, an element is always
considered to be strictly greater than a neighbor that is outside the array.
You must write an algorithm that runs in O(log n) time.
Example 1:
Input: nums = [1,2,3,1]
Output: 2
Explanation: 3 is a peak element and your function should return the index number 2.
Example 2:
Input: nums = [1,2,1,3,5,6,4]
Output: 5
Explanation: Your function can return either index number 1 where the peak element is 2, or
index number 5 where the peak element is 6.
Constraints:
• 1 <= [Link] <= 1000
• -231 <= nums[i] <= 231 - 1
• nums[i] != nums[i + 1] for all valid i.
Code: -
class Solution {
public int findPeakElement(int[] nums) {
int left = 0;
int right = [Link] - 1;
while (left < right) {
int mid = (left + right) / 2;
if (nums[mid] > nums[mid + 1]) {
right = mid;
} else {
left = mid + 1;
}
}
return left;
}
}
11 876. Middle of the Linked List
Given the head of a singly linked list, return the middle node of the linked list.
Input: head = [1,2,3,4,5]
Output: [3,4,5]
Explanation: The middle node of the list is node 3.
Example 2:
Input: head = [1,2,3,4,5,6]
Output: [4,5,6]
Explanation: Since the list has two middle nodes with values 3 and 4, we return the second
one.
Constraints:
• The number of nodes in the list is in the range [1, 100].
• 1 <= [Link] <= 100
CODE: -
class Solution {
public ListNode middleNode(ListNode head) {
ListNode slow=head,fast=head;
while(fast!=null && [Link]!=null){
slow=[Link];
fast=[Link];
}
return slow;
}
}
There is a cycle in a linked list if there is some node in the list that can be reached again by
continuously following the next pointer. Internally, pos is used to denote the index of the
node that tail's next pointer is connected to. Note that pos is not passed as a parameter.
Return true if there is a cycle in the linked list. Otherwise, return false.
Example 1:
Input: head = [3,2,0,-4], pos = 1
Output: true
Explanation: There is a cycle in the linked list, where the tail connects to the 1st node (0-
indexed).
Example 2:
Input: head = [1,2], pos = 0
Output: true
Explanation: There is a cycle in the linked list, where the tail connects to the 0th node.
Example 3:
Input: head = [1], pos = -1
Output: false
Explanation: There is no cycle in the linked list.
Constraints:
• The number of the nodes in the list is in the range [0, 104].
• -105 <= [Link] <= 105
• pos is -1 or a valid index in the linked-list.
CODE: -
public class Solution {
public boolean hasCycle(ListNode head) {
ListNode slow=head;
ListNode fast=head;
while(fast!=null && [Link]!=null){
slow=[Link];
fast=[Link];
if(slow==fast)
return true;
}
return false;
}
}
Merge the two lists into one sorted list. The list should be made by splicing together the
nodes of the first two lists.
Return the head of the merged linked list.
Example 1:
Input: list1 = [1,2,4], list2 = [1,3,4]
Output: [1,1,2,3,4,4]
Example 2:
Input: list1 = [], list2 = []
Output: []
Constraints:
• The number of nodes in both lists is in the range [0, 50].
• -100 <= [Link] <= 100
• Both list1 and list2 are sorted in non-decreasing order.
CODE: -
class Solution {
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
ListNode dummy=new ListNode(0);
ListNode curr=dummy;
while(l1!=null && l2!=null){
if([Link]<=[Link]){
[Link]=l1;
l1=[Link];
}
else{
[Link]=l2;
l2=[Link];
}
curr=[Link];
}
[Link]=l1!=null?l1:l2;
return [Link];
}
}
head.
Example 1:
Input: head = [1,2,3,4,5], n = 2
Output: [1,2,3,5]
Example 2:
Input: head = [1], n = 1
Output: []
Example 3:
Input: head = [1,2], n = 1
Output: [1]
Constraints:
• The number of nodes in the list is sz.
• 1 <= sz <= 30
• 0 <= [Link] <= 100
• 1 <= n <= sz
CODE: -
class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
ListNode res = new ListNode(0, head);
ListNode dummy = res;
for (int i = 0; i < n; i++) {
head = [Link];
}
while (head != null) {
head = [Link];
dummy = [Link];
}
[Link] = [Link];
return [Link];
}
}
reverse the nodes of the list from position left to position right, and return the reversed list.
Input: head = [1,2,3,4,5], left = 2, right = 4
Output: [1,4,3,2,5]
Example 2:
Input: head = [5], left = 1, right = 1
Output: [5]
Constraints:
• The number of nodes in the list is n.
• 1 <= n <= 500
• -500 <= [Link] <= 500
• 1 <= left <= right <= n
CODE: -
class Solution {
public ListNode reverseBetween(ListNode head, int left, int right) {
if (head == null || left == right) {
return head;
}
ListNode dummy = new ListNode(0);
[Link] = head;
ListNode prev = dummy;
for (int i = 0; i < left - 1; i++) {
prev = [Link];
}
ListNode cur = [Link];
for (int i = 0; i < right - left; i++) {
ListNode temp = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = temp;
}
return [Link];
}
}
should support all the functions of a normal queue (push, peek, pop, and empty).
Implement the MyQueue class:
• void push(int x) Pushes element x to the back of the queue.
• int pop() Removes the element from the front of the queue and returns it.
• int peek() Returns the element at the front of the queue.
• boolean empty() Returns true if the queue is empty, false otherwise.
Notes:
• You must use only standard operations of a stack, which means only push to
top, peek/pop from top, size, and is empty operations are valid.
• Depending on your language, the stack may not be supported natively. You may
simulate a stack using a list or deque (double-ended queue) as long as you use only a
stack's standard operations.
Example 1:
Input
["MyQueue", "push", "push", "peek", "pop", "empty"]
[[], [1], [2], [], [], []]
Output
[null, null, null, 1, 1, false]
Explanation
MyQueue myQueue = new MyQueue();
[Link](); // return 1, queue is [2]
[Link](); // return false
Constraints:
• 1 <= x <= 9
• At most 100 calls will be made to push, pop, peek, and empty.
• All the calls to pop and peek are valid.
CODE: -
class CustomStack {
private List<Integer> stackList;
public CustomStack() {
stackList = new ArrayList<>();
}
public boolean isEmpty() {
return [Link]();
}
public int top() {
if (isEmpty()) {
return -1;
}
return [Link]([Link]() - 1);
}
public int size() {
return [Link]();
}
public void push(int value) {
[Link](value);
}
public int pop() {
if (isEmpty()) {
return -1;
}
int topValue = [Link]([Link]() - 1);
[Link]([Link]() - 1);
return topValue;
}
}
class MyQueue {
private CustomStack stack1;
private CustomStack stack2;
public MyQueue() {
stack1 = new CustomStack();
stack2 = new CustomStack();
}
public void push(int x) {
while (![Link]()) {
[Link]([Link]());
}
[Link](x);
while (![Link]()) {
public int pop() {
return [Link]();
}
public int peek() {
return [Link]();
}
public boolean empty() {
return [Link]();
}
}
17 225. Implement Stack using Queues
Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack
should support all the functions of a normal stack (push, top, pop, and empty).
Implement the MyStack class:
• void push(int x) Pushes element x to the top of the stack.
• int pop() Removes the element on the top of the stack and returns it.
• int top() Returns the element on the top of the stack.
• boolean empty() Returns true if the stack is empty, false otherwise.
Notes:
• You must use only standard operations of a queue, which means that only push to
back, peek/pop from front, size and is empty operations are valid.
• Depending on your language, the queue may not be supported natively. You may
simulate a queue using a list or deque (double-ended queue) as long as you use only a
queue's standard operations.
Example 1:
Input
["MyStack", "push", "push", "top", "pop", "empty"]
[[], [1], [2], [], [], []]
Output
[null, null, null, 2, 2, false]
Explanation
MyStack myStack = new MyStack();
[Link](1);
[Link](2);
[Link](); // return 2
[Link](); // return 2
[Link](); // return False
Constraints:
• 1 <= x <= 9
• At most 100 calls will be made to push, pop, top, and empty.
• All the calls to pop and top are valid.
CODE: -
class MyStack {
Queue<Integer> q1;
Queue<Integer> q2;
public MyStack() {
q1=new LinkedList<>();
}
public int pop() {
int temp=0;
while(![Link]()){
temp =[Link]();
[Link]([Link]());
}
while([Link]()>1){
[Link]([Link]());
}
[Link]();
return temp;
}
public int top() {
int temp=0;
while(![Link]()){
temp =[Link]();
[Link]([Link]());
}
while(![Link]()){
[Link]([Link]());
}
[Link]();
return temp;
}
public boolean empty() {
if([Link]()==0){
return true;
}
return false;
}
}
18 496. Next Greater Element I
The next greater element of some element x in an array is the first greater element that
For each 0 <= i < [Link], find the index j such that nums1[i] == nums2[j] and
determine the next greater element of nums2[j] in nums2. If there is no next greater element,
then the answer for this query is -1.
Return an array ans of length [Link] such that ans[i] is the next greater element as
described above.
Example 1:
Input: nums1 = [4,1,2], nums2 = [1,3,4,2]
Output: [-1,3,-1]
Explanation: The next greater element for each value of nums1 is as follows:
- 4 is underlined in nums2 = [1,3,4,2]. There is no next greater element, so the answer is -1.
- 1 is underlined in nums2 = [1,3,4,2]. The next greater element is 3.
- 2 is underlined in nums2 = [1,3,4,2]. There is no next greater element, so the answer is -1.
Example 2:
Input: nums1 = [2,4], nums2 = [1,2,3,4]
Output: [3,-1]
Explanation: The next greater element for each value of nums1 is as follows:
- 2 is underlined in nums2 = [1,2,3,4]. The next greater element is 3.
- 4 is underlined in nums2 = [1,2,3,4]. There is no next greater element, so the answer is -1.
Constraints:
• 1 <= [Link] <= [Link] <= 1000
• 0 <= nums1[i], nums2[i] <= 104
• All integers in nums1 and nums2 are unique.
• All the integers of nums1 also appear in nums2.
CODE: -
class Solution {
public int[] nextGreaterElement(int[] nums1, int[] nums2) {
Stack<Integer> stack = new Stack<>();
Map<Integer, Integer> map = new HashMap<>();
for(int i = [Link] - 1; i >= 0; i--){
while (![Link]() && nums2[i] > [Link]()) [Link]();
if([Link]())
[Link](nums2[i], -1);
else
[Link](nums2[i], [Link]());
[Link](nums2[i]);
}
for(int i = 0; i < [Link]; i++)
nums1[i] = [Link](nums1[i]);
return nums1;
}
}
Companies
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and
removing all non-alphanumeric characters, it reads the same forward and backward.
Alphanumeric characters include letters and numbers.
Given a string s, return true if it is a palindrome, or false otherwise.
Example 1:
Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.
Example 2:
Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.
Example 3:
Input: s = " "
Output: true
Explanation: s is an empty string "" after removing non-alphanumeric characters.
• 1 <= [Link] <= 2 * 105
• s consists only of printable ASCII characters.
CODE: -
class Solution {
public boolean isPalindrome(String s) {
String a = [Link]();
int last = [Link]() - 1;
int start=0;
while(start<=last){
char cf = [Link](start);
char cl = [Link](last);
if(){
start++;
}else if(){
last--;
}else{
if(cf!=cl)return false;
start++;
last--;
}}
return true;
}
}
20 231. Power of Two
Given an integer n, return true if it is a power of two. Otherwise, return false.
An integer n is a power of two, if there exists an integer x such that n == 2x.
Example 1:
Input: n = 1
Output: true
Explanation: 20 = 1
Example 2:
Input: n = 16
Output: true
Explanation: 24 = 16
Example 3:
Input: n = 3
Output: false
Constraints:
• -231 <= n <= 231 – 1
CODE: -
class Solution {
public boolean isPowerOfTwo(int n) {
if(n==0 || n<0)
return false;
}
}
21 150. Evaluate Reverse Polish Notation
Medium
Topics
Companies
You are given an array of strings tokens that represents an arithmetic expression in a Reverse
Polish Notation.
Evaluate the expression. Return an integer that represents the value of the expression.
Note that:
• The valid operators are '+', '-', '*', and '/'.
• Each operand may be an integer or another expression.
• The division between two integers always truncates toward zero.
• There will not be any division by zero.
• The input represents a valid arithmetic expression in a reverse polish notation.
• The answer and all the intermediate calculations can be represented in a 32-
bit integer.
Example 1:
Input: tokens = ["2","1","+","3","*"]
Output: 9
Explanation: ((2 + 1) * 3) = 9
Example 2:
Input: tokens = ["4","13","5","/","+"]
Output: 6
Explanation: (4 + (13 / 5)) = 6
Explanation: ((10 * (6 / ((9 + 3) * -11))) + 17) + 5
= ((10 * (6 / (12 * -11))) + 17) + 5
= ((10 * (6 / -132)) + 17) + 5
= ((10 * 0) + 17) + 5
= (0 + 17) + 5
= 17 + 5
= 22
Constraints:
• 1 <= [Link] <= 104
• tokens[i] is either an operator: "+", "-", "*", or "/", or an integer in the range [-200,
200].
CODE: -
class Solution {
public int evalRPN(String[] tokens) {
Stack<String> st = new Stack<>();
for(int i=0;i<[Link];i++)
{
if(!tokens[i].equals("+") && !tokens[i].equals("-") && !tokens[i].equals("*") &&
!tokens[i].equals("/"))
[Link](tokens[i]);
else
{
int ans=0;
int val1=[Link]([Link]());
int val2=[Link]([Link]());
if(tokens[i].equals("+"))
ans = val1+val2;
else if(tokens[i].equals("-"))
ans = val2-val1;
else if(tokens[i].equals("*"))
ans = val1*val2;
else if(tokens[i].equals("/"))
ans = val2/val1;
String temp = [Link](ans);
[Link](temp);
}
}
return [Link]([Link]());
}
}
Companies
Hint
Given a binary string s and a positive integer n, return true if the binary representation of all
the integers in the range [1, n] are substrings of s, or false otherwise.
A substring is a contiguous sequence of characters within a string.
Example 1:
Input: s = "0110", n = 3
Output: true
Example 2:
Input: s = "0110", n = 4
Output: false
Constraints:
• 1 <= [Link] <= 1000
• s[i] is either '0' or '1'.
• 1 <= n <= 109
CODE:-
class Solution {
public boolean queryString(String s, int n) {
for(int i=1;i<=n;i++){
if()){
return false;
}
}
return true;
}
}