Merge Overlapping Intervals

Every thing has to merge…
Merge – combine, coalesce; absorb,team up ; join, consolidate; unite

Merge Overlapping Intervals :

Given a set of time intervals in any order, merge all overlapping intervals into one and output the result which should have only mutually exclusive intervals.

Let the intervals be represented as pairs of integers for simplicity.

For example: let the given set of intervals be {{1,3}, {2,4}, {5,7}, {6,8} }.

The intervals {1,3} and {2,4} overlap with each other, so they should be merged and become {1, 4}.

Similarly {5, 7} and {6, 8} should be merged and become {5, 8}

Final List will be {1,4} & {5,8}

A simple approach is to start from the first interval and compare it with all other intervals for overlapping, if it overlaps with any other interval, then remove the other interval from list and merge the other into the first interval. Repeat the same steps for remaining intervals after first.

Following is the detailed step by step algorithm :

1. Sort the intervals based on increasing order of starting time.
2. Push the first interval on to a stack.
3. For each interval do the following
a. If the current interval does not overlap with the stack top, push it.
b. If the current interval overlaps with stack top and ending time of current interval is more than that of stack top, update stack top with the ending time of current interval.
4. At the end stack contains the merged intervals.


Visualization – constructing life from a space inside our brains

why you should make visualization a daily practice

If you were ever involved in competitions or sports, chances are your coach asked you to imagine winning. How does it look, feel and sound? At the time, it might have seemed strange: reclining in a dark room, eyes closed, listening to imaginary scenarios. But there’s science behind visualization practices.

After all, Visualization is based on manipulating thought patterns through suggestions. Visualization actually have neurophysiological profiles. Nothing is being done to you; instead, it’s you who is tapping into something deep within the brain folds, accessing your creative power.

Successful people all over the world use visualization to spawn dreams into reality realms. Visualization is just concentrated dreaming. It’s mind over matter. It’s constructing life from a space inside our brains.

When digging a little deeper, visualization becomes less about winning and more about self-improvement than anything else. With visualization, you can create a world built from your own energies and desires. There are so many reasons why it will help you grow as a person. And there are so many ways you can do it.

Here are a few of the things that visualization can do for your well-being when it becomes part of your routine:

Visualization builds courage :

Visualization provides plenty of strength and courage to tackle daunting tasks. Afraid to get on stage? Nervous about an upcoming performance? Unsure of how to win that competition? Using visualization triggers hormones and synapses that make it easier to achieve those goals. When you’ve already envisioned the scenario, the real thing will feel familiar and much more feasible. It will be as if you’ve done it before. And inside your brain, you have.

Visualization combats negativity :

Visualization brings moments of positivity in a world sometimes full of negativity. So often, people respond to dreams with statements like, How will you do that? or That’s going to be so hard to accomplish. And yeah, sure, it will be hard, but you’re totally up for the challenge. During a visualization session, you get to live out your dreams despite what others say. It’s an effective way to battle that negative voice inside your own head, too.

Visualization bolsters creativity :

Visualization allows creative moments to exist, something the mind desperately needs. We tend to exist in scheduled spaces and confines of time. Fostering a practice that gives your mind a break from the mundane will be a relief to your psyche. Our brains need breaks—ones full of promise and fantastical visions, ones free from the chains of social constructs and full of creativity.

Visualization gathers energies :

Visualization fulfills the law of attraction, which facilitates dream building. Energy goes where attention flows. Want something badly enough? Then go ahead and dwell on it in healthy, optimistic ways. The more you visualize yourself living the life you want, the sooner universal energies will align with you to give you what you want. But don’t forget that being proactive is required and supports your visualization practice.

Visualization fosters purpose :

Visualization develops belief in self and creates a fulfilling life. When we lose hope, we lose so much. Hope is a catalyst for change. A life longing for something is worth the effort. Discover what you long for and visualize it every chance you get. You won’t be sorry. Actually, you’ll be amazed at how that personalized longing will propel you in directions you didn’t think were possible. Visualization can make that happen, but first you’ve got to believe.

Integrating salesforce SOAP API using C# .NET

Salesforce can be integrated with any .NET based application through the salesforce SOAP API. This article will show how to connect to salesforce and consume data within ASP.NET application.

Before we begin, there are a set of prerequisites that you need to get done in order to interact with salesforce API using the C# .NET.

  • Username and Password (salesforce logins)
  • SOAP API (WSDL file)
  • Security Token

Username and Password

You can register for a developer license in case you don’t have a user name and password at


To get WSDL SOAP API, need to login salesforce and click “Set up” on right top Corner. Then go Develop > API and right click on “Generate Enterprise WSDL” under Enterprise WSDL (as we using “Enterprise WSDL” web service) and click on “Save Link as….” to save (enterprise.wsdl) file to somewhere in your computer.

Security Token

My Setting > Personal > Reset My Security Token

.NET Application

Let’s start exploring the SOAP API functionality by creating a sample .Net application and connect into Salesforce.

Here are the steps that can be taken to setup the Enterprise WSDL:

Create new ASP.NET Empty Web Site

Adding a Web Service Reference to website

select “Add Service Reference”.

Click “Advanced..”

Click “Add Web Reference…”

In Add Web Reference dialog type path of saved “enterprise.wsdl” file in URL: and click “Enter” then change Web reference name to “SFDC” then click “Add Reference”.

Now Salesforce SOAP API added into our website

Now that the base website is created and a reference setup to the Enterprise WSDL, we can transition to writing code that calls the API.

The first step is to have Salesforce authenticate us as a user. Once the authentication with Salesforce is successful, additional authentication information, such as the Session ID and URL will be returned. This information is needed for subsequent API calls.

The Session ID can be cached in your application for periods less than the timeout period. Go to “Setup > Security Controls > Session Settings” to see what your timeout is.

Here is example code showing how to authenticate against Salesforce :

using SFDC;
protected void Page_Load(object sender, EventArgs e)
    bool ConnectionStatus;
    ConnectionStatus = ConnectSFDC();
    //rest of the code

public bool ConnectSFDC()
     string userName = "";
     string password = "...";
     string securityToken = ".........";

     System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
     SforceService sfdcBinding = null;
     LoginResult currentLoginResult = null;

     sfdcBinding = new SforceService();
           currentLoginResult = sfdcBinding.login(userName, password + securityToken);
     catch (System.Web.Services.Protocols.SoapException ex)
                // This is likley to be caused by bad username or password
                sfdcBinding = null
                //lOG ex
                return false;
      catch (Exception ex)
              // This is something else, probably communication issue
                sfdcBinding = null;
                //lOG ex
                return false;
       //Change the binding to the new endpoint
       sfdcBinding.Url = currentLoginResult.serverUrl;
       //Create a new session header object and set the session id to that returned by the login
       sfdcBinding.SessionHeaderValue = new SessionHeader();
       sfdcBinding.SessionHeaderValue.sessionId = currentLoginResult.sessionId;
       // create required sessions 
       return true;

Regenerating SessionID in ASP.NET

Creating New ASP.NET_SessionId & Attaching Old ASP.NET_SessionId Values to New ASP.NET_SessionId

public void RegenerateSessionId()

System.Web.SessionState.SessionIDManager manager = new System.Web.SessionState.SessionIDManager();
string oldId = manager.GetSessionID(System.Web.HttpContext.Current);

string newId = manager.CreateSessionID(System.Web.HttpContext.Current);

bool isAdd = false, isRedir = false;
manager.SaveSessionID(System.Web.HttpContext.Current, newId, out isRedir, out isAdd);

HttpApplication ctx = (HttpApplication)HttpContext.ApplicationInstance;
HttpModuleCollection mods = ctx.Modules;
System.Web.SessionState.SessionStateModule ssm = (SessionStateModule)mods.Get(“Session”);
System.Reflection.FieldInfo[] fields = ssm.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
SessionStateStoreProviderBase store = null;
System.Reflection.FieldInfo rqIdField = null, rqLockIdField = null, rqStateNotFoundField = null;
foreach (System.Reflection.FieldInfo field in fields)
if (field.Name.Equals(“_store”)) store = (SessionStateStoreProviderBase)field.GetValue(ssm);
if (field.Name.Equals(“_rqId”)) rqIdField = field;
if (field.Name.Equals(“_rqLockId”)) rqLockIdField = field;
if (field.Name.Equals(“_rqSessionStateNotFound”)) rqStateNotFoundField = field;
object lockId = rqLockIdField.GetValue(ssm);
if ((lockId != null) && (oldId != null)) store.ReleaseItemExclusive(System.Web.HttpContext.Current, oldId, lockId);
rqStateNotFoundField.SetValue(ssm, true);
rqIdField.SetValue(ssm, newId);

UZVAL – Statistics – Total Hits-22,222, Total Visitors-6623, Total Posts – 93

Six years back I started posting certain postings in this blog for learning purpose.

Today it got 22,222 hits, Total Visitors-6623, Total Posts – 93.

During this tenure I had Learned a lot & Implemented my level best, Professionally & Personally.

Today i am feeling that i had completed one life cycle.

Heartful Thanks to My Well-Wishers who had given me good opportunities.

Now we all know lot of significant CHANGES (new versions, new libraries, new frameworks) evolved in .Net Stack.

Hope TOGETHER (Integrations & Collaborations) we learn and implement NEW needful CHANGES Professionally & Personally for a better life-style & society.


Ujjwala Datta Kalluri.


If any Suggestion, please submit it below :

2015 in Review – Wish You Happy New Year

Wish You Happy Happy Happy New Year,

Time is free, but it’s priceless.
You can’t own it, but you can use it.
You can’t keep it, but you can spend it.
Once you’ve lost it, you can never get it back…

Years, Months, Weeks, Days, Hours , Minutes, Seconds… Its Transforming…

Hope we utilise our Time for well-being in a constructive way & we all have Good Health, Relationships, Prosperity, Contentment & Happiness.

Annual Report – 2015 for this blog

Here’s an excerpt:

In 2015 this blog was viewed about 5,300 times,

there were only 2 new posts,

The busiest day of the year was Apr 29th with 83 views.

Visitors are from 69 countries in all!

Most visitors came from India. The United States & The Srilanka.

Comma separated / delimited string to a table in SQL Server

Recently, I came across a piece of TSQL code that would take a comma separated string as an input and parse it to return a single column table from it.
CREATE FUNCTION [dbo].[UDF_string_to_table]

@string VARCHAR(8000),
@delimiter CHAR(1)
RETURNS @output TABLE(CommaSeparatedString VARCHAR(256))


DECLARE @start INT, @end INT
SELECT @start = 1, @end = CHARINDEX(@delimiter, @string)

WHILE @start < LEN(@string) + 1 BEGIN
IF @end = 0
SET @end = LEN(@string) + 1

INSERT INTO @output (CommaSeparatedString) VALUES(SUBSTRING(@string, @start, @end – @start))

SET @start = @end + 1
SET @end = CHARINDEX(@delimiter, @string, @start)



select * from UDF_string_to_table(‘1,2,3′,’,’)