Skip to main content

Posts

Showing posts from 2021

Black cells in a chessboard Problem Code: BLACKCEL

Given n (n is even), determine the number of black cells in an n×n chessboard Input Format The only line of the input contains a single integer  n n . Output Format Output the number of black cells in an  n × n n × n  chessboard. Constraints 2 ≤ n ≤ 100 2 ≤ n ≤ 100 n n  is even Sample Input 1  8 Sample Output 1  32 Explanation There are  32 32  black cells and  32 32  white cells in an  8 × 8 8 × 8  chessboard. So the answer is  32 32 . import java . util .*; public class BlackCell {             public static void main ( String [] args ) throws Exception {             Scanner sc = new Scanner ( System . in );                         int n = sc . nextInt ();             System . out . println ( n * n / 2 );                         sc . close ();         }         }

Find the index that divides an array into two non-empty subarrays with equal sum | Naive Approach O(n2) | Code in Java

Given an integer array, find an index that divides it into two non-empty subarrays having an equal sum. For example, consider array  {-1, 6, 3, 1, -2, 3, 3} . The element 3 at index 2 divides it into two non-empty subarrays  {-1, 6}  and  {1, -2, 3, 3}  having the same sum. Please note that the problem specifically targets  subarrays  that are contiguous (i.e., occupy consecutive positions) and inherently maintains the order of elements. A naive solution would calculate the sum of the left and right subarray for each array element and print the index if both sums are the same. The time complexity of this approach  O(n 2 ) ,  import java . util .*; /* Given an integer array, find an index that divides it into two non-empty contiguous subarrays having an equal sum. Input : [-1, 6, 3, 1, -2, 3, 3] Output: 2 Explanation: The element 3 at index 2 divides the array into two non-empty subarrays `[-1, 6]` and `[1, -2, 3, 3]` having the same sum. • The solution should return -1 if no partition

Find the index that divides an array into two non-empty subarrays with equal sum | O(n) || Code in Java

Given an integer array, find an index that divides it into two non-empty subarrays having an equal sum. For example, consider array   {-1, 6, 3, 1, -2, 3, 3} . The element 3 at index 2 divides it into two non-empty subarrays   {-1, 6}   and   {1, -2, 3, 3}   having the same sum. Please note that the problem specifically targets   subarrays   that are contiguous (i.e., occupy consecutive positions) and inherently maintains the order of elements. We can solve this problem in  O(n)  time by using extra space. The idea is to preprocess the array and store the sum of every index’s left and right subarray in two auxiliary arrays. Then we can calculate the left and right sum in constant time for any index. To improve the space complexity to constant, preprocess the given array and store the sum of all array elements in a variable. Then traverse the array and maintain another variable to store the left subarray sum till the current item. Now we can calculate the right subarray sum in constant

Physical Verification for PwD Candidates only for IITs || IMPORTANT NOTICE FOR PHYSICAL VERIFICATION PROCESS AND DATE RANGES FOR PwD CANDIDATES || JoSAA 2021

The Joint Seat Allocation Authority (JoSAA) 2021 has been set up by the Ministry of Education [erstwhile Ministry of Human Resources Development (MHRD)] to manage and regulate the joint seat allocation for admissions to 114 institutes for the academic year 2021-22. This includes 23 IITs,  31 NITs, IIEST Shibpur, 26 IIITs, and 33 Other-Government Funded Technical Institutes (Other-GFTIs). Admission to all the academic programs offered by these Institutes will be made through a single platform. Exclusive:  Joint Seat Allocation Authority 2021 | IITs, NITs, IIEST, IIITs, and Other-GFTIs for the Academic Year 2021-22 This year the PwD candidates would be allowed a longer time duration along with the choice for selection of the institute where they would like to report for physical verifications of their PwD status vis-à-vis the information mentioned in the documents uploaded by the candidates, as per the following schemes.  Note: For Physical Verification of PwD candidates during Interval