November 24, 2019

#LeetCode: Java Solution of Bitwise AND of Numbers Range problem

Bitwise AND of Numbers Range
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.

Example 1: Input: [5,7], Output: 4
Example 2:Input: [0,1], Output: 0

Part 2.6: Leet Code Solutions For Java Coding Interview Round

Valid Parenthesis String

Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this string is valid. We define the validity of a string by these rules:
  • Any left parenthesis '(' must have a corresponding right parenthesis ')'.
  • Any right parenthesis ')' must have a corresponding left parenthesis '('.
  • Left parenthesis '(' must go before the corresponding right parenthesis ')'.
  • '*' could be treated as a single right parenthesis ')' or a single left parenthesis '(' or an empty string.
  • An empty string is also valid.

Part 2.5: Leet Code Solutions For Java Coding Interview Round

Perform String Shifts

You are given a string s containing lowercase English letters, and a matrix shift, where shift[i] = [direction, amount]:

direction can be 0 (for left shift) or 1 (for right shift).
amount is the amount by which string s is to be shifted.
A left shift by 1 means remove the first character of s and append it to the end.
Similarly, a right shift by 1 means remove the last character of s and add it to the beginning.
Return the final string after all operations.

Example 1:
Input: s = "abc", shift = [[0,1],[1,2]]
Output: "cab"
Explanation:
[0,1] means shift to left by 1. "abc" -> "bca"
[1,2] means shift to right by 2. "bca" -> "cab"

Example 2:
Input: s = "abcdefg", shift = [[1,1],[1,1],[0,2],[1,3]]
Output: "efgabcd"
Explanation:
[1,1] means shift to right by 1. "abcdefg" -> "gabcdef"
[1,1] means shift to right by 1. "gabcdef" -> "fgabcde"
[0,2] means shift to left by 2. "fgabcde" -> "abcdefg"
[1,3] means shift to right by 3. "abcdefg" -> "efgabcd"

Constraints:
1 <= s.length <= 100
s only contains lower case English letters.
1 <= shift.length <= 100
shift[i].length == 2
0 <= shift[i][0] <= 1
0 <= shift[i][1] <= 100

GIT URL: Java Solution of Leet Code's Perform String Shifts problem
Java Solution

Last Stone Weight
We have a collection of stones, each stone has a positive integer weight.

Each turn, we choose the two heaviest stones and smash them together.

Suppose the stones have weights x and y with x <= y.  The result of this smash is:

If x == y, both stones are totally destroyed;
If x != y, the stone of weight x is totally destroyed, and the stone of weight y has new weight y-x.
At the end, there is at most 1 stone left.  Return the weight of this stone (or 0 if there are no stones left.)

Example 1:
Input: [2,7,4,1,8,1]
Output: 1

Explanation:
We combine 7 and 8 to get 1 so the array converts to [2,4,1,1,1] then,
we combine 2 and 4 to get 2 so the array converts to [2,1,1,1] then,
we combine 2 and 1 to get 1 so the array converts to [1,1,1] then,
we combine 1 and 1 to get 0 so the array converts to [1] then that's the value of last stone.

Note:
1 <= stones.length <= 30

1 <= stones[i] <= 1000

GIT URL: Java Solution of Leet Code's Last Stone Weight problem
Java Solution
Product of Array Except Self
Given an array nums of n integers where n > 1,  return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].

Example:
Input:  [1,2,3,4]
Output: [24,12,8,6]
Constraint: It's guaranteed that the product of the elements of any prefix or suffix of the array (including the whole array) fits in a 32 bit integer.

Note: Please solve it without division and in O(n).

Algorithm:
1). create a new array 'output' with the length same as the input array 'nums'. In 'output' array for a given index i, output[i] would contain the product of all the numbers to the left of i and product of all the numbers to the right of i.
2). We will first find the product of all the elements to the left. To do this let's assume in 'output' array for a given index i, output[i] would contain the product of all the numbers to the left of i.
3). For the element at index '0', there are no elements to the left, that's why output[0]= 1
4). output[i-1] will have the product of elements to the left of 'i-1', to do this we need to multiply nums[i - 1] with output[i-1]
5). Declare a int variable 'right', which cntains the product of all the elements to the right.
6). For the last element (the element at index 'length-1') there are no elements to the right, that's why R will be 1.

7). We need to update output[i] it will be the product of output[i] and 'right'. After doing this we need to update 'right' (it would be product of 'right' and nums[i]).

GIT URL: Java Solution of Leet Code's Product of Array Except Self problem
Java Solution

-K Himaanshu Shuklaa..

Part 2.4: Leet Code Solutions For Java Coding Interview Round

Length of Last Word

Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word (last word means the last appearing word if we loop from left to right) in the string.

Part 2.3: Leet Code Solutions For Java Coding Interview Round

Counting Elements

Given an integer array arr, count element x such that x + 1 is also in arr. If there're duplicates in arr, count them separately.

Part 2.2: Leet Code Solutions For Java Coding Interview Round

Single Number
Given a non-empty array of integers, every element appears twice except for one. Find that single one.

Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

Example 1
Input: [2,2,1]. Output: 1

Example 2
Input: [4,1,2,1,2]. Output: 4

Part 2.1: Leet Code Solutions For Java Coding Interview Round

1). Remove K Digits

Given a non-negative integer number represented as a string, remove k digits from the number so that the new number is the smallest possible.

Part 1: Java Algorithms For Coding Interview Round

Two Sum 
Given an array of integers, return indices of the two numbers such that they add up to a specific target. Let us assume that each input would have exactly one solution, and you may not use the same element twice. e.g: nums = [1,2,8,9], target = 9, it will return [0,8]

November 23, 2019

Prime Flix Brothel to undergo a name change!

Prime Flix is coming up with yet another interesting web-series titled Brothel. Now, the latest update is that the makers of the web series have now decided to change the title to #Mandi.

November 22, 2019

Rio Kapadia and Gargi Patel bagged Ullu App's upcoming series 'Kasak'

Ullu App is coming up with a web-series 'Kasak', which is based on a life of a rape victim. After roping in 'Hate Story' actress Ihana Dhillon, Sharhaan Singh, Vineet Raina the makers have now finalized Rio Kapadia and Gargi Patel to play an important roles in the series.

November 21, 2019

Calendar Girls Satarupa Pyne cries foul!

Satarupa Pyne, who made her Bollywood debut with Madhur Bhandarkar's Calendar Girls revealed a shocking details about a horrific shooting experience.

November 16, 2019

#JNUFact: Is the fee hike in JNU justified?

Total Number Of Students, Departments and courses offered in JNU

Let's first start with the number of students in JNU and number of departments , along with the courses offered. Here is how it looks:

Total number of students in JNU=8000.

Between the two categories, we have 72% of the campus covered:

  • 4578 students (57%) are from social sciences, language, literature & arts.
  • 1210 students (15%) are from International studies.
That means, almost 55% of the total student strength i.e. 4359 students are doing M.Phil. or Ph.D.

November 14, 2019

BARC TV Ratings- Week 45, 2019


Top 10 Hindi GEC Channel
  1. Dangal : 1062033
  2. SONY SAB : 713275
  3. STAR Plus : 645875
  4. Zee TV : 589598
  5. Sony Entertainment Television : 565928
  6. Colors : 530950
  7. Big Magic : 491524
  8. STAR Bharat : 312930
  9. STAR Utsav : 177916
  10. Colors Rishtey : 167957

Preetisheel Singh basks in the 'shining' glory of Bala

Fresh from the super success of Housefull 4 and appreciation for her work for Ujda Chaman, ace makeup, hair and prosthetic character designer Preetisheel Singh is basking in the glory of critical acclaim for her latest film Bala... or should we say, for having constructed Ayushmann Khurrana's shining baldpate. Tch tch! ;-)