## Sunday, 11 October 2015

## Wednesday, 23 September 2015

# Hackerrank Insert a node into a sorted doubly linked list Solution

##
**Problem Statement**

You’re given the pointer to the head node of a sorted doubly linked list and an integer to insert into the list. Create a node and insert it into the appropriate position in the list. The head node might be NULL to indicate that the list is empty.##
**Source Code:**

```
Node* SortedInsert(Node *head,int data)
{
// Complete this function
// Do not write the main method.
Node *temp = new Node;
temp->data = data;
temp->next = NULL;
temp->prev = NULL;
if(head == NULL){
head = temp;
}else{
Node *temp1 = temp;
temp->next = head;
head = temp;
while(temp!= NULL){
temp1 = temp;
temp = temp->next;
if(temp!=NULL){
if(temp1->data>temp->data){
int tdata;
tdata = temp1->data;
temp1->data = temp->data;
temp->data = tdata;
}
}
}
}
return head;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

## Thursday, 6 August 2015

# GRK Web

We are a passionate Computer Science Engineering Students who believe in our dreams.

We are application Developers who develop awesome applications for PC and Mobile platforms.

We build the Future Today.

Our Official website : grkweb.com

Facebook Page : facebook.com/grkweb

## Wednesday, 5 August 2015

# C++ Diamond Pattern

C++ program to print the diamond pattern using '#' symbols. In this program two for loops are used to print the pattern. The first loop prints the upper part to the diamond ( triangle part ). The second for loop prints the lower part of the diamond (an inverted triangle ) . By combining both of the triangles an diamond pattern structure is formed.

## PROGRAM CODE:

```
#include<iostream>
using namespace std;
int main()
{
int i,j,k=1,s=6,l;
for(i=0;i<5;i++,k-=2,s-=1)
{
for(l=s-1;l>=0;l--)
cout<<' ';
for(j=k;j<0;j++)
cout<<"#";
cout<<endl;
}
k = 9;
s = 0;
for(i=0;i<5;i++,k-=2,s+=1)
{
for(l=s;l>=0;l--)
cout<<' ';
for(j=k;j>0;j--)
cout<<"#";
cout<<endl;
}
return 0;
}
```

## OUTPUT:

#

# # #

# # # # #

# # # # # # #

# # # # # # # # #

# # #

# # # # #

# # # # # # #

# # # # # # # # #

# # # # # # #

# # # # #

# # #

# # # # #

# # #

#

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

## Saturday, 18 April 2015

# Hackerrank Print the elements of a linked list solution

## Problem Statement

This challenge is part of a tutorial track by MyCodeSchool and is accompanied by a video lesson.

If you’re new to working with linked lists, this is a great exercise to get familiar with them. You’re given the pointer to the head node of a linked list and you need to print all its elements in order, one element per line. The head pointer may be null, i.e., it may be an empty list. In that case, don’t print anything!

## Source code:

```
/*
Print elements of a linked list on console
head pointer input could be NULL as well for empty list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
void Print(Node *head)
{
// This is a "method-only" submission.
// You only need to complete this method.
while(head!=NULL){
cout<<head->data<<endl;
head = head->next;
}
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

# Hackerrank Print in Reverse solution

## Problem Statement

This challenge is part of a tutorial track by MyCodeSchool and is accompanied by a video lesson.Youâ€™re given the pointer to the head node of a linked list and you need to print all its elements in reverse order from tail to head, one element per line. The head pointer may be null meaning that the list is empty - in that case, donâ€™t print anything!

## Soruce code:

```
/*
Print elements of a linked list in reverse order as standard output
head pointer could be NULL as well for empty list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
void ReversePrint(Node *head)
{
// This is a "method-only" submission.
// You only need to complete this method.
int a[100],i=0;
while(head!=NULL){
a[i] = head->data;
i++;
head = head->next;
}
for(int j = i-1;j>=0;j--){
cout<<a[j]<<endl;
}
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)# Hackerrank Reverse a doubly linked list solution

## Problem Statement

This challenge is part of a tutorial track by MyCodeSchoolYou’re given the pointer to the head node of a doubly linked list. Reverse the order of the nodes in the list. The head node might be NULL to indicate that the list is empty.

## Source Code:

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)`/* Reverse a doubly linked list, input list may also be empty Node is defined as struct Node { int data; Node *next; Node *prev; } */ Node* Reverse(Node* head) { Node *cur = head,*temp = new Node; // Complete this function // Do not write the main method. while(cur !=NULL){ temp->next = cur->next; temp->prev = cur->prev; cur->next = temp->prev; cur->prev = temp->next; cur = temp->next; if(cur!=NULL){ head = cur; } } return head; }`

# Hackerrank Merge two sorted linked lists solution

## Problem Statement

This challenge is part of a tutorial track by MyCodeSchool

You’re given the pointer to the head nodes of two sorted linked lists. The data in both lists will be sorted in ascending order. Change the next pointers to obtain a single, merged linked list which also has data in ascending order. Either head pointer given may be null meaning that the corresponding list is empty.

## Source code:

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)`/* Merge two sorted lists A and B as one linked list Node is defined as struct Node { int data; struct Node *next; } */ Node* MergeLists(Node *headA, Node* headB) { // This is a "method-only" submission. // You only need to complete this method Node *head=NULL, *cur,*prev = NULL; Node *curA,*curB; head = headA; cur = head; curB = headB; while(curB !=NULL){ if(cur== NULL){ head = headB; break; }else{ if(cur->data > curB->data){ curA = curB; curB = curB->next; curA->next = cur; if(prev == NULL){ head = curA; }else{ prev->next = curA; } prev = cur; cur = cur->next; }else{ if(cur->next !=NULL){ prev = cur; cur = cur->next; }else{ cur->next = curB; break; } }} }return head; }`

# Hackerrank Reverse a linked list solution

## Problem Statement

This challenge is part of a tutorial track by MyCodeSchool and is accompanied by a video lesson.You’re given the pointer to the head node of a linked list. Change the next pointers of the nodes so that their order is reversed. The head pointer given may be null meaning that the initial list is empty.

## source code:

```
/*
Reverse a linked list and return pointer to the head
The input list will have at least one element
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
Node* Reverse(Node *head)
{
// Complete this method
Node *prev = NULL;
Node *cur = head;
Node *next ;
while(cur!=NULL){
next = cur->next;
cur->next = prev;
prev = cur;
cur = next;
}
head = prev;
return head;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)# Hackerrank Insert a node at a specific position in a linked list solution

## Problem Statement

This challenge is part of a tutorial track by MyCodeSchool and is accompanied by a video lesson.

You’re given the pointer to the head node of a linked list, an integer to add to the list and the position at which the integer must be inserted. Create a new node with the given integer, insert this node at the desired position and return the head node. A position of 0 indicates head, a position of 1 indicates one node away from the head and so on. The head pointer given may be null meaning that the initial list is empty.

## source code:

```
/*
Insert Node at a given position in a linked list
The linked list will not be empty and position will always be valid
First element in the linked list is at position 0
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
Node* InsertNth(Node *head, int data, int position)
{
// Complete this method only
// Do not write main function.
Node *cur = new Node,*temp = new Node;
temp->data = data;
temp->next = NULL;
if(head == NULL){
head = temp;
}else{
int i=0;
cur = head;
while(cur!=NULL){
if(position == 0){
temp->next = cur;
head= temp;
}
else if(i==position-1){
temp->next = cur->next;
cur ->next = temp;
}else{
}i++;
cur= cur->next;
}
}
return head;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

# Hackerrank Detect Cycle solution

## Problem Statement

This challenge is part of a tutorial track by MyCodeSchool

You’re given the pointer to the head node of a linked list. Find whether the list contains any cycle (or loop). A linked list is said to contain cycle if any node is re-visited while traversing the list. The head pointer given may be null meaning that the list is empty.

## Source Code:

```
/*
Detect loop in a linked list
List could be empty also
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
int HasCycle(Node* head)
{
// Complete this function
// Do not write the main method
Node* fast = head, *slow = head;
while(fast!= NULL){
fast = fast->next->next;
slow = slow->next;
if(fast == slow){
return 1;
}
}return 0;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

# Hackerrank Find Merge Point of Two Lists solution

## Problem Statement

This challenge is part of a tutorial track by MyCodeSchool

You’re given the pointer to the head nodes of two linked lists that merge together at some node. Find the node at which this merger happens. The two head nodes will be different and neither will be NULL.

## Source code:

```
/*
Find merge point of two linked lists
Node is defined as
struct Node
{
int data;
Node* next;
}
*/
int FindMergeNode(Node *headA, Node *headB)
{
// Complete this function
// Do not write the main method.
Node *tempB;
while(headA!=NULL){
tempB = headB;
while(tempB!=NULL){
if(tempB == headA){
return tempB->data;
}
tempB = tempB->next;
}
headA = headA->next;
}
return headA->data;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

# Hackerrank Insert a node at the tail of a linked list solution

## Problem Statement

This challenge is part of a tutorial track by MyCodeSchool and is accompanied by a video lesson.You’re given the pointer to the head node of a linked list and an integer to add to the list. Create a new node with the given integer, insert this node at the tail of the linked list and return the head node. The head pointer given may be null meaning that the initial list is empty.

## source code:

```
/*
Insert Node at the end of a linked list
head pointer input could be NULL as well for empty list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
Node* Insert(Node *head,int data)
{
// Complete this method
Node *cur= new Node;
cur->data = data;
cur->next = NULL;
if(head==NULL){
head = cur;
}else{
Node *curr = new Node;
curr = head;
while(curr->next !=NULL){
curr = curr->next;
}
curr->next = cur;
}
return head;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

# Hackerrank Delete a Node solution

## Problem Statement

This challenge is part of a tutorial track by MyCodeSchool and is accompanied by a video lesson.You’re given the pointer to the head node of a linked list and the position of a node to delete. Delete the node at the given position and return the head node. A position of 0 indicates head, a position of 1 indicates one node away from the head and so on. The list may become empty after you delete the node.

## Source code:

```
/*
Delete Node at a given position in a linked list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
Node* Delete(Node *head, int position)
{
// Complete this method
Node *cur;
cur = head;
if(position == 0){
head = head->next;
}else{
int i = 0;
while(cur!= NULL){
if(i == (position)-1){
cur -> next = (cur->next)->next;
break;
}else{
cur = cur->next;
}
i++;
}
}
return head;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

# Hackerrank Insert a node at the head of a linked list solution

## Problem Statement

This challenge is part of a tutorial track by MyCodeSchool and is accompanied by a video lesson.

You’re given the pointer to the head node of a linked list and an integer to add to the list. Create a new node with the given integer, insert this node at the head of the linked list and return the new head node. The head pointer given may be null meaning that the initial list is empty.

## Source Code:

```
/*
Insert Node at the begining of a linked list
Initially head pointer argument could be NULL for empty list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
return back the pointer to the head of the linked list in the below method.
*/
Node* Insert(Node *head,int data)
{
// Complete this method
Node *cur = new Node;
cur ->data = data;
cur ->next = NULL;
if(head == NULL ){
head = cur;
}else{
cur ->next = head;
head = cur;
}
return head;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

# Hackerrank Compare two linked lists Solution

## Problem Statement

This challenge is part of a tutorial track by MyCodeSchoolYou’re given the pointer to the head nodes of two linked lists. Compare the data in the nodes of the linked lists to check if they are equal. The lists are equal only if they have the same number of nodes and corresponding nodes contain the same data. Either head pointer given may be null meaning that the corresponding list is empty.

## source code:

```
/*
Compare two linked lists A and B
Return 1 if they are identical and 0 if they are not.
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
int CompareLists(Node *headA, Node* headB)
{
// This is a "method-only" submission.
// You only need to complete this method
while((headA!= NULL) || (headB!= NULL)){
if((headA == NULL) || (headB == NULL))
return 0;
if(headA->data != headB->data){
return 0;
}
headA = headA->next;
headB = headB->next;
}
return 1;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

# Hackerrank Delete duplicate-value nodes from a sorted linked list Solution

##
**Problem Statement**

This challenge is part of a tutorial track by MyCodeSchool

You're given the pointer to the head node of a sorted linked list, where the data in the nodes is in ascending order. Delete as few nodes as possible so that the list does not contain any value more than once. The given head pointer may be null indicating that the list is empty.

For now do not be concerned with the memory deallocation. In common abstract data structure scenarios, deleting an element might also require deallocating the memory occupied by it. For an initial intro to the topic of dynamic memory please consult:http://www.cplusplus.com/doc/tutorial/dynamic/

## Source code:

```
/*
Remove all duplicate elements from a sorted linked list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
Node* RemoveDuplicates(Node *head)
{
// This is a "method-only" submission.
// You only need to complete this method.
Node *cur = head;
while(cur->next!=NULL){
if(cur->data == cur->next->data)
cur->next = cur->next->next;
else
cur = cur->next;
}
return head;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

## Friday, 17 April 2015

# Hackerrank Get Node Value Solution

**Problem Statement**

This challenge is part of a tutorial track by MyCodeSchool

You’re given the pointer to the head node of a linked list and a specific position. Counting backwards from the tail node of the linked list, get the value of the node at the given position. A position of 0 corresponds to the tail, 1 corresponds to the node before the tail and so on.

##
**Solution:**

```
/*
Get Nth element from the end in a linked list of integers
Number of elements in the list will always be greater than N.
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
int GetNode(Node *head,int positionFromTail)
{
// This is a "method-only" submission.
// You only need to complete this method.
int n = 0;
Node *cur = head;
while(cur!=NULL){
n++;
cur = cur->next;
}
n --;
cur = head;
while(cur!=NULL){
if(n == positionFromTail){
return cur->data;
}
n--;
cur = cur ->next;
}
return 0;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

## Thursday, 26 March 2015

# Hackerrank Bigger is Greater Solution

## Problem Statement

Given a word w, rearrange the letters of w to construct another word s in such a way that, s is lexicographically greater than w. In case of multiple possible answers, find the lexicographically smallest one.## Source Code:

This program uses STL, if you have solved it without using STL comment the source code below.

```
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
char a[1000];
int aa[1000]={0};
cin>>a;
int n = strlen(a);
if(next_permutation(a,a+n)){
cout<<a<<endl;
}else{
cout<<"no answer"<<endl;
}
}
return 0;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

# Hackerrank Manasa and Stones Solution

**Problem Statement**

Manasa is out on a hike with friends. She finds a trail of stones with numbers on them. She starts following the trail and notices that two consecutive stones have a difference of either a or b . Legend has it that there is a treasure trove at the end of the trail and if Manasa can guess the value of the last stone, the treasure would be hers. Given that the number on the first stone was 0 , find all the possible values for the number on the last stone.

**Note**: The numbers on the stones are in increasing order.

## Source Code:

```
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int t;
cin>>t;
while(t--){
int n,a,b,gt,lw;
cin>>n>>a>>b;
if(a>b){
gt =a ;
lw = b;
}else{
lw = a;
gt = b;
}
int ans = lw*(n-1);
n--;
int dif = gt-lw;
cout<<ans<<" ";
if(dif>0){
while(n--){
ans += dif;
cout<<ans<<" ";
}
}
cout<<endl;
}
return 0;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

## Sunday, 15 March 2015

# Hackerearth Balance strings Solution

## PROBLEM STATEMENT:

Balance strings, by definition, are the strings that contain all the characters of the alphabet, from a to z, equal no of times. eg- abcdefghijklmnopqrstuvwxyz is a balanced string, aabb is not.

Input:

First line contains number of test cases T. Each test case contains a string S which made up of only lowercase characters.

First line contains number of test cases T. Each test case contains a string S which made up of only lowercase characters.

Output:

For each test case print Yes if the string is balanced string else print No.

For each test case print Yes if the string is balanced string else print No.

Constraints:

1<=T<=10

1<=|S|<=1000

1<=T<=10

1<=|S|<=1000

## SOURCE CODE:

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerearth. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)`#include <iostream> using namespace std; int main() { int t; cin>>t; while(t--){ char arr[10000]; int a[500]={0},mx=0; cin>>arr; for(int i=0;arr[i]!='\0';i++){ int temp = arr[i]-97; a[temp]++; if(a[temp]>mx){ mx = a[temp]; } } int flag = 1; for(int i=0;i<26;i++){ if(a[i]!=mx){ flag = 0; } } if(flag) { cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } } return 0; }`

## Saturday, 14 March 2015

# Hackerearth What is the string made of? solution

##
**PROBLEM STATEMENT:**

You are given a string, which contains entirely of decimal digits (0-9). Each digit is made of a certain number of dashes, as shown in the image below. For instance 1 is made of 2 dashes, 8 is made of 7 dashes and so on.

You have to write a function that takes this string message as an input and returns a corresponding value in terms of a number. This number is the count of dashes in the string message.

Note:

0 consists of 6 dashes, 1 consists of 2 dashes, 2 consists of 5 dashes, 3 consists of 5 dashes, 4 consists of 4 dashes, 5 consists of 5 dashes, 6 consists of 6 dashes, 7 consists of 3 dashes [though the figure shows that 7 consists of 4 dashes but due to minor mistake in the problem please write your solution assuming 7 consists of 3 dashes], 8 consists of 7 dashes, 9 consists of 6 dashes.

Constraints

- String message will contain at least one digit, but not more than 100
- Each character in code will be a digit ('0'-'9').

##
**SOURCE CODE:**

`#include <iostream>`

`#include <string.h>`

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerearth. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)`using namespace std; int main() { int arr[100]={6,2,5,5,4,5,6,3,7,6},ans = 0; char str[10000] ; cin>>str; for(int i=0;str[i]!='\0';i++) { int temp = str[i] -48 ; ans += arr[temp]; } cout<<ans<<endl; return 0; }`

## Monday, 9 March 2015

# Hackerrank Pangrams Solution

**Problem Statement**

Roy wanted to increase his typing speed for programming contests. So, his friend advised him to type the sentence "The quick brown fox jumps over the lazy dog" repeatedly because it is a pangram. ( pangrams are sentences constructed by using every letter of the alphabet at least once. )

After typing the sentence several times, Roy became bored with it. So he started to look for other pangrams.

Given a sentence s , tell Roy if it is a pangram or not.

### (Explanation for the code is available in the first comment)

**Source Code:**

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)`#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <stdio.h> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ char arr[10000]; gets(arr); int a[150]={0}; for(int i =0;arr[i]!='\0';i++){ char t; t = tolower(arr[i]); int n = t; if(n>0) { a[n]++; //cout<<n<<endl; } } int flag = 1; for(int i = 97;i<123;i++){ if(a[i]==0){ flag = 0; } } if(flag == 1) cout<<"pangram"<<endl; else cout<<"not pangram"<<endl; return 0; }`

## Sunday, 8 March 2015

# Hackerrank Valid PAN format Solution

**Problem Statement**

The equivalent of SSN in India is a PAN number, which is unique to each of its citizens. In any of the country's official documents, the PAN number is listed as follows

```
<char><char><char><char><char><digit><digit><digit><digit><char>
```

Your task is to figure out if the PAN number is valid or not. A valid PAN number will have all its letters in uppercase and digits in the same order as listed above.

**Source Code:**

```
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int t;
cin>>t;
while(t--){
char a[100];
int flag = 1;
cin>>a;
for(int i=0;a[i]!='\0';i++){
int temp = a[i];
if(i<5){
//cout<<a[i]<<" ";
//cout<<temp<<" ";
if(temp<65 || temp>90){
flag = 0;
}
}else if(i<9){
if(temp<48 || temp>57){
flag = 0;
}
}else{
if(temp<65 || temp>90){
flag = 0;
}
}
}
if(flag){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
return 0;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

# Hackerrank Angry Professor Solution

**Problem Statement**

The professor is conducting a course on Discrete Mathematics to a class of N students. He is angry at the lack of their discipline, and he decides to cancel the class if there are less than K students present after the class starts.

Given the arrival time of each student, your task is to find out if the class gets cancelled or not.

**Source Code:**

```
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int t;
cin>>t;
while(t--){
int n,k,temp,cnt=0;
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>temp;
if(temp<=0){
cnt++;
}
}
if(cnt>=k){
cout<<"NO"<<endl;
}else{
cout<<"YES"<<endl;
}
}
return 0;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

## Tuesday, 3 March 2015

# Hackerrank Sherlock and Array Solution

**Problem Statement**

Русский \| 中文

Watson gives an array

Formally, find an

Watson gives an array

*A1,A2...AN*to Sherlock. Then he asks him to find if there exists an element in the array, such that, the sum of elements on its left is equal to the sum of elements on its right. If there are no elements to left/right, then sum is considered to be zero.Formally, find an

*i*, such that,*A1+A2...Ai-1*=*Ai+1+Ai+2...AN*.## Source Code:

```
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int t;
cin>>t;
while(t--){
int arr[1000000],n,flag = 0;
unsigned long long lsum=0,rsum = 0;
cin>>n;
for(int i=0;i<n;i++){
cin>>arr[i];
rsum += arr[i];
}
for(int i=0;i<n;i++)
{
rsum -= arr[i];
if(i>0){
lsum += arr[i-1];
}
if(lsum == rsum){
flag = 1;
}
}
if(flag == 1){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
return 0;
}
```

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

## Thursday, 19 February 2015

# Expense Manager Android Application Ver 0.1.2

Expense Manager Android Application |

### Features:

Simple user interface.Easy to Add or remove the balance amount.

Add the amount using + icon.

View summary of the expense report by using the search icon in the action bar.

Summary of the Expenses will be displayed with the amount of percentage for each of the category.

Reset button to reset the data's to default settings.

To Reset the balance data's click on the settings option in your mobile and select reset option which will reset the balance amount to zero.

---------

New features can be added to the application on user request. :)

Please notify any bugs or suggestion below.

---------

### Contact Us:

Blog : http://gokulrajkumar.blogspot.in/Facebook Page: https://www.facebook.com/pages/GRK/512045565588875

More about developer : http://gokulrajkumar.tk/