Total amount of time covered by the intervals

There’s a room with a TV and people are coming in and out to watch it. The TV is on only when there’s at least a person in the room. For each person that comes in, we record the start and end time. We want to know for how long the TV has been on. In other words, given a list of arrays of time intervals, write a function that calculates the total amount of time covered by the intervals.

For example:
input = [(1,4), (2,3)]
output = 3
input = [(4,6), (1,2)]
output = 3
input = [(1,4), (6,8), (2,4), (7,9), (10, 15)]
output = 11

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] numArray = { 1, 4, 6, 8, 2, 4, 7, 9, 10, 15 };
            //Sort the array based on starting point
            numArray = BubbleSort(numArray);
            ArrayList numArrayList = new ArrayList();
            numArrayList.AddRange(numArray);
            for (int i = 1; i = (int)numArrayList[i + 1]) && ((int)numArrayList[i] = (int)numArrayList[i + 1]) && ((int)numArrayList[i] >= (int)numArrayList[i + 2]))
                {
                    numArrayList.RemoveAt(i + 1);
                    numArrayList.RemoveAt(i + 1);
                    i = i - 2;
                }
            }
            int totalTime = 0;
            for (int i = 0; i < numArrayList.Count - 1; i = i + 2)
            {
                totalTime = totalTime + ((int)numArrayList[i + 1] - (int)numArrayList[i]);
            }
            Console.WriteLine("Total time covered = " + totalTime);
        }

        public static int[] BubbleSort(int[] numArray)
        {
            int temp1, temp2;
            for (int pass = 0; pass <= numArray.Length - 4; pass++)
            {
                for (int i = 0; i  numArray[i + 2])
                    {
                        temp1 = numArray[i];
                        temp2 = numArray[i + 1];
                        numArray[i] = numArray[i + 2];
                        numArray[i + 1] = numArray[i + 3];
                        numArray[i + 2] = temp1;
                        numArray[i + 3] = temp2;
                    }
                }
            }
            return numArray;
        }
    }
}

Output
=======
Total time covered = 11
Press any key to continue . . .
Posted in Information Technology | Leave a comment

Summation of different combinations

You have a string of digits say 123. You can insert a + or – sign in front of every digit. Find all of the different possibilities and return the sum of all results.

For example:
+1+2+3 = 6
+12+3 = 15
+123 = 123
+1+23 = 24

-1-2-3 = 6

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace ConsoleApplication1
{
    class Program
    {
        public static int sum = 0;
        static void Main(string[] args)
        {
            string str = "123";
            GenerateCombinations(str, 0, "", "");
            Console.WriteLine("Total Sum = " + sum);
        }

        public static void GenerateCombinations(string str, int startPos, string tempStrWithoutSymbol, string tempStrWithSymbol)
        {
            if (tempStrWithoutSymbol == str)
            {
                Console.WriteLine(tempStrWithSymbol + " = " + Calculate(tempStrWithSymbol));
                sum = sum + Calculate(tempStrWithSymbol);
            }

            else
            {
                for (int len = 1; len <= str.Length - startPos; len++)
                {
                    GenerateCombinations(str, startPos + len, tempStrWithoutSymbol + str.Substring(startPos, len), tempStrWithSymbol + "+" + str.Substring(startPos, len));
                    GenerateCombinations(str, startPos + len, tempStrWithoutSymbol + str.Substring(startPos, len), tempStrWithSymbol + "-" + str.Substring(startPos, len));
                }
            }
        }

        public static int Calculate(string strExp)
        {
            DataTable dt = new DataTable();
            return ((int)dt.Compute(strExp, ""));
        }
    }
}

Output
=======
+1+2+3 = 6
+1+2-3 = 0
+1-2+3 = 2
+1-2-3 = -4
+1+23 = 24
+1-23 = -22
-1+2+3 = 4
-1+2-3 = -2
-1-2+3 = 0
-1-2-3 = -6
-1+23 = 22
-1-23 = -24
+12+3 = 15
+12-3 = 9
-12+3 = -9
-12-3 = -15
+123 = 123
-123 = -123
Total Sum = 0
Press any key to continue . . .
Posted in Information Technology | Leave a comment

Application stages and timelines for OCI

Overall it took 5+ months to complete the entire application process.

Application Status Remarks Date of Status
Your Passport and OCI Card have now reached CKGS Application Centre from the Embassy / Consulate and is being sorted and will be ready for dispatch through the Pre-Paid Envelope label provided by you.
Your AWB Number is XXXXXXXXXXXX.
To Track the progress of your shipment, log onto the site of your Service Provider and enter your AWB Number.
02/11/2017
Your Documents have now reached CKGS application centre from the Embassy / Consulate.
Your document(s) is being sorted and will be ready for shipment shortly. Please continue tracking your application status online.
02/11/2017
Your printed OCI Card is ready for match-up with your US Passport / Foreign Passport. Please complete the OCI match-up process and refer to the email sent to you from CKGS with further details.
To make sure you receive our alerts / updates, add noreply.usa@ckgs.com to your white list. Please continue tracking your application status online.
10/16/2016
Your OCI card has been dispatched from India to the Embassy / Consulate. It will take 1 to 2 weeks before it arrives. Please continue tracking your application status online. 09/27/2016
Application is under process at the Embassy / Consulate for further scrutinization and may take upto 6 to 8 weeks for next update. Please continue tracking your application status online. 08/31/2016
Your Application is under process at the Embassy / Consulate. Please continue tracking your application status online. 08/29/2016
Your application has been processed at the CKGS Application Centre and is in transit to the Indian Embassy/Consulate for decision making.
Please continue tracking your application status online.
08/26/2016
We have received your incomplete / missing documents and we are verifying the same.
You will receive an update shortly on the progress of your application.
Please continue tracking your application status online.
ADDITIONAL DOCUMENTS RECEIVED (FEDEX XXXX XXXX XXXX) 08/26/2016
Your Application is on hold due to the incomplete / missing documents as mentioned under the REMARKS column. Only once the above documents are received by us at CKGS and post verification, will we be able to continue to process your application.
Please refer to our EMAIL sent to you from CKGS with further details.To make sure you receive our alerts / updates, add noreply.usa@ckgs.com to your white list / Approved / Safe Sender list.
1.PHOTO UNACCEPTABLE TOO ORANGE. 08/23/2016
We have received your payment and we are verifying the same. If the payment made is complete, you will receive a payment receipt shortly. If there is any further discrepancy, you will receive an update. Please continue tracking your application status online. 08/23/2016
Your application has been received and is under process in CKGS. Please continue tracking your application status online. Your tracking id is USAXXXXXXXXX 08/23/2016
Posted in Business, Travel | Leave a comment

PPF (Public Provident Fund) Rules

http://www.bankofindia.co.in/pdf/PPFrules_14%20.pdf

One deposit with a minimum amount of Rs.500/- is mandatory in each financial year.
Posted in Business | Leave a comment

SD Card writing speed for shooting movies with Canon DSLR

When shooting movies, use a large-capacity SD card rated SD
Speed Class 6 or higher. If you use a card having a slow writing speed, a five-level indicator might appear on the right of the screen during movie shooting. It indicates how much data has not yet been written to the card (remaining capacity of the internal buffer memory). The slower the card, the faster the indicator will climb upward. If the indicator becomes full, movie shooting will stop automatically. If the card has a fast writing speed, the indicator will either not appear or the level (if displayed) will hardly go upward.

Posted in Hobbies, Travel | Tagged , , | Leave a comment

Drop boxes for syringe disposal in Seattle

http://www.kingcounty.gov/depts/health/communicable-diseases/hiv-std/patients/drug-use-harm-reduction/needle-disposal.aspx

Posted in Health and wellness | Leave a comment

Check if a string can become empty by recursively deleting a given sub-string

Given a string “str” and another string “sub_str”. We are allowed to delete “sub_str” from “str” any number of times. The task is to find if “str” can become empty by removing “sub_str” again and again.

Examples:

Input : str = “GEEGEEKSKS”, sub_str = “GEEKS”
Output : Yes
Explanation : In the string GEEGEEKSKS, we can first
delete the substring GEEKS from position 4.
The new string now becomes GEEKS. We can
again delete sub-string GEEKS from position 1.
Now the string becomes empty.

Input : str = “GEEGEEKSSGEK”, sub_str = “GEEKS”
Output : No
Explanation : In the string it is not possible to make the
string empty in any possible manner.

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        public static int flag = 0;
        public static void Main(string[] args)
        {
            string str = "KEEKEEKK";
            string subStr = "KEEK";
            RecursiveDeletion(str, subStr);
            if(flag == 0)
            {
                Console.WriteLine("No");
            }
        }

        public static void RecursiveDeletion(string str, string subStr)
        {
            if (str == null || str.Length == 0)
            {
                Console.WriteLine("Yes");
                flag = 1;
            }
            else
            {
                for (int i = 0; i <= str.Length - subStr.Length && flag == 0; i++)
                {
                    if (str.Substring(i, subStr.Length) == subStr)
                    {
                        RecursiveDeletion(str.Remove(i, subStr.Length), subStr);
                    }
                }
            }
        }
    }
}

Output
=======
Yes
Press any key to continue . . .
Posted in Information Technology | Leave a comment