DAA LAB 1 Ghanshyam
DAA LAB 1 Ghanshyam
LAB FILE
22103057
DEPARTMENT OF COMPUTER SECTION – A
SCIENCE AND ENGINEERING GROUP - G3
DSA
LAB-01
TASK – 01.1
Reverse a 1-D Array
Q1) Given a Binary 2-D Matrix in which 0 represents water and 1 represents land. An island is surrounded by water and is
formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the Matrix are all
surrounded by water. Print Number of islands.
Input
#include <iostream>
#include <vector>
Output
TASK - 02
Maximum Subarray [Leetcode-Q53]
Q2) Given an integer array nums, find the Subarray with the largest sum, and return its sum.
Constraints:
Input
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int MAX=INT_MIN;
int sum=0;
for (int x: nums){
sum+=x;
if (sum>MAX)
MAX=sum;
if(sum<0)
sum=0;
}
return MAX;
}
};
Output