Search This Blog

Thursday, 20 August 2026

API Authentication

Reference · Identity & Access

API Authentication Methods

Four common ways a client proves who it is to a server, ordered from least to most secret-sensitive. Each diagram shows the exchange step by step.

01

Basic Authentication

sequenceDiagram autonumber participant C as Client participant S as Server C->>S: Requests resource S->>C: Requests username/password C->>S: Sends username/password S->>C: Returns resource

Credentials travel in plaintext (Base64-encoded, not encrypted) on every request. Simple to implement, but the password is re-exposed constantly.

Not recommended for production
Secret exposure
02

Token Authentication

sequenceDiagram autonumber participant C as Client participant S as Server C->>S: User logs in S->>C: Sends encrypted token C->>S: Sends request with token S->>C: Returns resource

The client logs in once, receives a token, then sends that token with every subsequent request instead of the password itself.

Great for SPAs & mobile apps
Secret exposure
03

OAuth Authentication

sequenceDiagram autonumber participant C as Client participant U as User participant A as Auth Server participant R as Resource Server C->>U: Authorization request U->>C: Authorization grant C->>A: Authorization grant A->>C: Access token C->>R: Access token R->>C: Returns resource

A dedicated authorization server issues scoped access on the user's behalf, so the client never sees the password — only a limited-permission token.

Google / Facebook login
Secret exposure
04

API Key Authentication

sequenceDiagram autonumber participant C as Client participant S as API Server participant D as Database C->>S: Create key S->>C: Store key C->>S: Access with key S->>D: Resource authorized

Each client is issued a unique, static key that identifies and authorizes it. Lightweight, but the key must be rotated and stored carefully since it doesn't expire on its own.

Best for internal APIs & small projects
Secret exposure

Saturday, 26 April 2025

Creating a NuGet Package Feed to Host Artifacts

Step-by-Step Guide: Creating a NuGet Package Feed to Host Artifacts

🔹 Step 1: Create a C# Class Library and Generate NuGet Package

  1. Open Visual Studio.
  2. Go to File → New → Project.
  3. Select Class Library (.NET Standard) or .NET Framework.
  4. Name the project (e.g., ClassLibrary1) and click Create.
  5. Right-click the project in Solution Explorer and select Properties.
  6. Go to the Package tab.
  7. Check Generate NuGet package on build.
  8. Fill in metadata fields as needed (Package ID, Version, Author, etc.).
  9. Build the project in Release mode.

Note: The .nupkg file will be generated in bin\Release\.

🔹 Step 2: Set Up a NuGet Feed in Azure DevOps

  1. Go to Azure DevOps Portal and log in.
  2. Create a new project named Own-Artifacts.
  3. Click Create.
  4. In the left-hand menu, click Artifacts.
  5. Click + Create Feed.
  6. Enter the following:
    • Name: Feed-OwnNuGet
    • Visibility: People in your cloud user
  7. Click Create.

🔹 Step 3: Publish the NuGet Package to Azure DevOps Feed

  1. Ensure nuget.exe is installed and available in your system path.
  2. Open a Command Prompt or Developer Command Prompt.
  3. Run the following command:
nuget.exe push -Source "https://pkgs.dev.azure.com/clouduser/Own-Artifacts/_packaging/Feed-OwnNuGet/nuget/v3/index.json" -ApiKey az "D:\hc-git\ClassLibrary1\bin\Release\ClassLibrary-hc1.1.0.0.nupkg"

Note: Replace the path with the actual location of your .nupkg file.



NuGet Feed

✅ Summary

  • You created a class library and generated a NuGet package.
  • You set up a private NuGet feed in Azure DevOps.
  • You published the package to your own feed.

Monday, 29 April 2024

Elasticsearch - Nodes, clusters, and shards

What is Ingress

Ingress.

Enabling traffic.

  • Openning the cluster to receive external traffic.
Traffic routing
  • Defining the traffic routes to backend services.
Traffic Reliability
  • Ensure Reliable, Secure communication.

Monday, 21 August 2023

Orchestration Tools

Orchestration Tools.

Orchestration - automation that supports processes and workflows, such as provisioning resources.

  • Scale up and scale down applications on request
  • Auto scale applications based on usage
  • Create self-healing systems by spinning down unhealthy node and replacing them with new ones
Orchestration Tools Examples

  • Docker Swarm
  • kubernetes
  • Zookeeper
  • Terraform

Configuration Management Tools

Configuration Management Tools.

What is configuration Management?

  • Resolves configuration drift
  • Maintaining desired state
  • The process of systematically handling chnages to a system
  • Maintain integrity of a system over time
  • Automation plays an key role
    • Puppet
    • Ansibel
    • Chef
    • Salt

Examples

Ansible
  • Open Source
  • Declarative configuration
  • YAML configuration files
  • No control server needed - but ansible tower available
  • No agents needed, just python and ssh


Puppet
  • Declarative configuration
  • Manage state through a UI
  • Custom modules use puppet DSL
  • Pushes chnages to clients using control server and agents installed on clients.


Chef
  • Procedural configuration
  • Agent/Server
  • Uses chef DSL


Salt
  • Declarative configuration
  • Agent (minions) /Server (Master) - but can support agentless
  • Uses YAML
  • Support for event-driven automation


Note:
Idempotent Behavior - is an operation that can be applied multiple times without changing the result beyound the initial application. E.g. 1 x 1 = 1
- Configuration management tools will avoid reapeating tasks.
- The desired state is maintained even if you run it multiple times.

Why use Configuration Management?
  • Quick provisioning of New servers
  • Quick Recovery from Critical Events
  • No more snowflake
  • Version controlfor the server Envirnment
  • Replaced Environment

Build Automation Tools

Build Automation Tools.

Examples

  • Java: ant, maven, gradle
  • JavaScript: npm, grunt, gulp
  • Packer: build machine images and containers

Saturday, 19 August 2023

DevOps Tools Periodic Table

Search the world's most comprehensive index of full-text books.

The Periodic Table of DevOps Tools is the industry's go-to resource for identifying best-of-breed tools across the software delivery lifecycle

DevOps Periodic table - https://digital.ai/learn/devops-periodic-table/

Recent challenge that you faced

Interview Question: Tell us about a recent challenge that you faced in your current role, and how you overcame it.

Problem: To develop a microservice-based high-performance pricing execution engine (In the cloud with concurrent processing, scalability, and observability) to solve complex configure price quote (CPQ), use cases by processing the data of the Salesforce platform (Current eco-system falls short in terms of performance).

Use case: Large global enterprise companies often deal with significant amounts of complexity when creating configurations and pricing within their quoting process. They have to work with hundreds of thousands of pricing rules and configuration rules each time they create or update a quote.

Brainstorming: We had brainstormed with the team and break down the problem statement into smaller pieces/modules, and everyone has taken end-to-end ownership/responsibility of the one module. here I have taken ownership of observability.

On my Plate: I have to find out the most suitable solution for observability that support involves measuring, collecting, and analyzing various diagnostics signals from a distributed system. These signals may include metrics, traces, logs, events, profiles.

My Challenges: Develop an end-to-end diligent plan/roadmap for Observability under high uncertainty, and demonstrate how to implement observability throughout the organization from scratch. I visualized there was a steep learning curve.

Team Immediate thought: As we are developers who have experience in the Microsoft technology stack. In front of us, we have an easy/time-tested/proven approach to use Azure Application insight and buy the Phobos NuGet for Enterprise Application Monitoring using Akka.NET for Actor monitoring, Concurrent processing, Distributed Tracing.

Action/Overcome: I was made a decision to evaluate/explore the best option for observability.

I had made the to-do list as per attention-to-details and a sense of urgency, it helps me to navigate, stay prioritized, and be on track.

  1. Made the holistic roadmap with a deadline timeline.
  2. Technology Evaluation: Find out the Observability technologies Landscape which solves the use case. In the journey, I have learned OpenTracing, Akka.NET Phobos, Microsoft Application Insights, StatsD, Graphite time-series database, Grafan, Prometheus, Jaeger, Zipkin, Elasticsearch, Kubernetes, deployment of the container, Akka.NET framework, and persistence for observability.
  3. Proof of Concept (POC): Write the code for multiple POC for Observability how to support trace, logs, metrics for application performance measures, and trace distributed calls.
  4. Documentation: Made the documentation for How to integrate the Observability Nuget in other microservices.
  5. Demo to a Larger audience in Organization: Based on the most suitable technology of the observability use case, I had given the demo on OpenTracing.io standard. I am happier to answered to team’s questions on Observability.
  6. Draw the roadmap - Observability journey has started to implement its own reusable observability Nuget (Which contains metric and tracing telemetry) in an application, demonstrate the application performance gain in observability tool using metrics show in Grafana, and made the support team more efficient to find out issue by analyzing the distributed trace in Jeager.

Achievement: Developed solution designs in collaboration with software architects that improved product support team efficiency by 100% and made it easy for a development team to debug applications.

Machine Learning

Machine Learning.

A category of artificial intelligence that uses algorithms to analyze data, learn from the data, and then make inferences about the data.

Use cases

  • Mark email as spam or not spam
  • Categorize articles as technology, sports or politics
  • Determine if test is negative or positive
  • Facial recognition
  • Fraud detection/prevention
  • Revenue predictions
  • Success rate measurements
  • Credit scoring

Friday, 18 August 2023

Data Analytics VS Data Science

Data Analytics Data Science
Definition
Process and analyze data sets to model and communicate answer to specific questions with actionable data.

A multi-disciplinary field that specializes in exposing insights from large data sets.
Skills
  • Statistics
  • Computer Science
  • AI (machine learning, deep learning, etc.)

  • Scientific method
  • Advanced mathematics
  • Computer Science
  • AI (machine learning, deep learning, etc.)
  • Data Analysis
Goals
  • Provide solution to known unknowns
  • Answer specific questions

  • Understand phenomena
  • Expose unknown unknowns
  • To identify the right questions to ask
  • Find better ways to analyze data

Tuesday, 1 August 2023

Programming eBooks - read online

Search the world's most comprehensive index of full-text books.

Programming eBooks - https://books.google.co.in/books

Elasticsearch _msearch

When using the msearch (multi-search) API in Elasticsearch, you can search across multiple indices in a single request. Each search query in the msearch request can be targeted to a specific index..

Create Elasticsearch Index

PUT product-index
{
    "settings": {
        "analysis": {
            "normalizer": {
                "lowercaseNormalizer": {
                    "type": "custom",
                    "filter": [
                        "lowercase",
                        "asciifolding"
                    ]
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "Product": {
                "type": "object",
                "properties": {
                    "ProductName": {
                        "type": "keyword",
                        "normalizer": "lowercaseNormalizer"
                    },
                    "ProductCode": {
                        "type": "keyword",
                        "normalizer": "lowercaseNormalizer"
                    },
                    "ProductDescription": {
                        "type": "text"
                    },
                    "ProductFamily": {
                        "type": "keyword",
                        "normalizer": "lowercaseNormalizer"
                    },
                    "Color": {
                        "type": "keyword"
                    }
                }
            }
        }
    }
}     
       

Adding sample data/records

        
#Add first Document in elasticsearch 
PUT /product-index/_doc/1
{
    "Product": {
        "ProductName": "CBC Anti Virus",
        "ProductCode": "Network",
        "ProductDescription": "APAC",
        "ProductFamily": "Sales Cloud",
        "Color": "Silver"
    }
}


PUT /product-index/_doc/2
{
    "Product": {
        "ProductName": "CBC Esoteric",
        "ProductDescription": "CBC Panel - 1",
        "ProductFamily": "Hardware",
        "Color": "BLUE"
    }
}

PUT /product-index/_doc/3
{
    "Product": {
        "ProductName": "CBC Oncology",
        "ProductCode": "CBC Health",
        "ProductFamily": "Software"
    }
}

PUT /product-index/_doc/4
{
    "Product": {
        "ProductName": "CBC Panel",
        "ProductCode": "Secure Wifi",
        "ProductDescription": "Only One Charge Type"
    }
}

PUT /product-index/_doc/5
{
    "Product": {
        "ProductName": "CBC Panel (Invitro)",
        "ProductCode": "Secure Wifi",
        "ProductDescription": "CBC Panel",
        "ProductFamily": "Hardware",
        "Color": "GREEN"
    }
}


PUT /product-index/_doc/6
{
    "Product": {
        "ProductName": "CBC Panel - Beijing",
        "ProductCode": "CBC Panel",
        "ProductDescription": "Only One Charge Type",
        "ProductFamily": "Software",
        "Color": "BLUE"
    }
}


PUT /product-index/_doc/7
{
    "Product": {
        "ProductName": "Esoteric",
        "ProductCode": "CBC",
        "ProductFamily": "Marketing Cloud",
        "Color": "WHITE"
    }
}


PUT /product-index/_doc/8
{
    "Product": {
        "ProductName": "Oncology",
        "ProductCode": "Network",
        "ProductDescription": "CBC",
        "ProductFamily": "Sales Cloud",
        "Color": "WHITE"
    }
}

        

Create Elasticsearch Index

PUT order-index
{
    "settings": {
        "analysis": {
            "normalizer": {
                "lowercaseNormalizer": {
                    "type": "custom",
                    "filter": [
                        "lowercase",
                        "asciifolding"
                    ]
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "Order": {
                "type": "object",
                "properties": {
                    "OrderCode": {
                        "type": "keyword",
                        "normalizer": "lowercaseNormalizer"
                    },
                    "Description": {
                        "type": "text"
                    },
                    "Family": {
                        "type": "keyword",
                        "normalizer": "lowercaseNormalizer"
                    },
                    "ProductName": {
                        "type": "keyword",
                        "normalizer": "lowercaseNormalizer"
                    },
                    "ProductId": {
                        "type": "keyword"
                    }
                }
            }
        }
    }
}    
       

Adding sample data/records

        
#Add first Document in elasticsearch 
PUT /order-index/_doc/5c57754b-86a6-41f1-a4af-de65b531fe8f
{
    "Order": {
        "OrderCode": "Network",
        "Description": "APAC",
        "Family": "Sales Cloud",
        "ProductName": "CBC Anti Virus",
        "ProductId": 1
    }
}


PUT /order-index/_doc/218c4907-89c2-482f-90cc-61dd7e27f999
{
    "Order": {
        "OrderCode": "Network",
        "Description": "CBC Panel - 1",
        "Family": "Hardware",
        "ProductName": "CBC Esoteric",
        "ProductId": 2
    }
}

 

        

View data/regcords

GET /product-index/_search
GET /order-index/_search


Search case-insensitive records

In the request body, provide the search queries in a newline-separated JSON format. Each search query should have two parts: the header and the search body. The header contains information about the index and search type, while the search body contains the actual search query DSL.

#Try 1
POST http://localhost:9200/_msearch
Content-type:application/json
Payload as below


{"index" : "product-index"}
{"query": {"match": {"Product.OrderCode": "Network"}}, "from" : 0, "size" : 10}
{"index" : "order-index"}
{"query": {"match": {"Order.OrderCode": "Network"}}}

       


Note

  • Text fields are analyzed.
  • For keyword fields we need to add custom elasticsearch setting for analysis.


Reference

Tuesday, 4 July 2023

Multiple Index Query

The following request searches the product-index and order-index indices.

Create Elasticsearch Index

PUT product-index
{
  "settings": {
    "analysis": {
      "normalizer": {
        "lowercaseNormalizer": {
          "type": "custom",
          "filter": ["lowercase", "asciifolding"]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "ProductName": {
        "type": "keyword",
        "normalizer": "lowercaseNormalizer"
      },
     "ProductCode": {
        "type": "keyword",
        "normalizer": "lowercaseNormalizer"
      },
      "ProductDescription": {
        "type": "text"
      },
      "ProductFamily": {
        "type": "keyword",
        "normalizer": "lowercaseNormalizer"
      },
      "Color": {
        "type": "keyword"
      }
    }
  }
}       
       

Adding sample data/records

        
#Add first Document in elasticsearch 
PUT /product-index/_doc/1
{
  "ProductName": "CBC Anti Virus",
  "ProductCode": "Network",
  "ProductDescription": "APAC",
  "ProductFamily": "Sales Cloud",
  "Color": "Silver"
}


PUT /product-index/_doc/2
{
  "ProductName": "CBC Esoteric",
  "ProductDescription": "CBC Panel - 1",
  "ProductFamily": "Hardware",
  "Color": "BLUE"
}

PUT /product-index/_doc/3
{
  "ProductName": "CBC Oncology",
  "ProductCode": "CBC Health",
  "ProductFamily": "Software"
}

PUT /product-index/_doc/4
{
  "ProductName": "CBC Panel",
  "ProductCode": "Secure Wifi",
  "ProductDescription": "Only One Charge Type"
}

PUT /product-index/_doc/5
{
  "ProductName": "CBC Panel (Invitro)",
  "ProductCode": "Secure Wifi",
  "ProductDescription": "CBC Panel",
  "ProductFamily": "Hardware",
  "Color": "GREEN"
}


PUT /product-index/_doc/6
{
  "ProductName": "CBC Panel - Beijing",
  "ProductCode": "CBC Panel",
  "ProductDescription": "Only One Charge Type",
  "ProductFamily": "Software",
  "Color": "BLUE"
}


PUT /product-index/_doc/7
{
  "ProductName": "Esoteric",
  "ProductCode": "CBC",
  "ProductFamily": "Marketing Cloud",
  "Color": "WHITE"
}


PUT /product-index/_doc/8
{
  "ProductName": "Oncology",
  "ProductCode": "Network",
  "ProductDescription": "CBC",
  "ProductFamily": "Sales Cloud",
  "Color": "WHITE"
}

        

Create Elasticsearch Index

PUT order-index
{
    "settings": {
        "analysis": {
            "normalizer": {
                "lowercaseNormalizer": {
                    "type": "custom",
                    "filter": [
                        "lowercase",
                        "asciifolding"
                    ]
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "OrderCode": {
                "type": "keyword",
                "normalizer": "lowercaseNormalizer"
            },
            "Description": {
                "type": "text"
            },
            "Family": {
                "type": "keyword",
                "normalizer": "lowercaseNormalizer"
            },
            "ProductName": {
                "type": "keyword",
                "normalizer": "lowercaseNormalizer"
            },
            "ProductId": {
                "type": "keyword"
            }
        }
    }
}      
       

Adding sample data/records

        
#Add first Document in elasticsearch 
PUT /order-index/_doc/5c57754b-86a6-41f1-a4af-de65b531fe8f
{
    "OrderCode": "Network",
    "Description": "APAC",
    "Family": "Sales Cloud",
    "ProductName": "CBC Anti Virus",
    "ProductId": 1
}


PUT /order-index/_doc/218c4907-89c2-482f-90cc-61dd7e27f999
{
    "OrderCode": "Network",
    "Description": "CBC Panel - 1",
    "Family": "Hardware",
    "ProductName": "CBC Esoteric",
    "ProductId": 2
}

 

        

View data/regcords

GET /product-index/_search
GET /order-index/_search


Search case-insensitive records

#Try 1
GET /order-index,product-index/_search
{
    "_source": {
        "include": [
            "Id",
            "OrderCode",
            "ProductId",
            "ProductCode"
        ],
        "exclude": []
    },
    "from": 0,
    "size": 100,
    "track_total_hits": true,
    "query": {
        "bool": {
            "filter": [
                {
                    "bool": {
                        "should": [
                            {
                                "query_string": {
                                    "query": "*Network*",
                                    "fields": [
                                        "ProductCode",
                                        "OrderCode"
                                    ],
                                    "boost": 7
                                }
                            }
                        ]
                    }
                }
            ]
        }
    }
}
       


Note

  • Text fields are analyzed.
  • For keyword fields we need to add custom elasticsearch setting for analysis.


Reference

Saturday, 5 November 2022

Elasticsearch Reindex / migration

ElasticSearch: Zero downtime reindexing
ElasticSearch has a solution to the problem, index aliases. The alias is like a symbolic link which can point to one or more indices. It gives us the flexibility to create a new index in the background and making the changes in a way that is almost unnoticeable to the application.

Friday, 4 November 2022

Elasticsearch

Elasticsearch is the distributed search and analytics engine at the heart of the Elastic Stack.

Reference

Thursday, 3 November 2022

AWS OpenSearch Deployment Best Practices

  • 3 Dedicated Master Nodes
  • Offload cluster managment task like health checks and maintain routing and cluster state.

  • Data Nodes deployed in multiples of 3
  • Store the data in shards and perform searches, query request, and CRUD operations.

  • Deploy across 3AZs
  • Destribute the data nodes equally across 3 AZs for the hightest availability.

Saturday, 22 October 2022

Validate Subsequence

List array = new List() { 5, 1, 22, 25, 6, -1, 8, 10 };
List sequence = new List { 1, 6, -1, 10 };
bool isValid = IsValidSubsequence(array, sequence);
Console.WriteLine(isValid);
//Expected Output: true
      

Solution 1.
public static bool IsValidSubsequence0(List array, List sequence)
{
    int seqIdx = 0;
    for (int arrIdx = 0; arrIdx < array.Count && seqIdx < sequence.Count; arrIdx++)
    {
        if (array[arrIdx] == sequence[seqIdx])
        {
            seqIdx++;
        }
    }
    return seqIdx == sequence.Count;
}
      

Test case

Test Case 1
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, -1, 10]
}
Test Case 2
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 25, 6, -1, 8, 10]
}
Test Case 3
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 6, -1, 8, 10]
}
Test Case 4
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [22, 25, 6]
}
Test Case 5
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, 10]
}
Test Case 6
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 10]
}
Test Case 7
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, -1, 8, 10]
}
Test Case 8
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [25]
}
Test Case 9
{
  "array": [1, 1, 1, 1, 1],
  "sequence": [1, 1, 1]
}
Test Case 10
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 25, 6, -1, 8, 10, 12]
}
Test Case 11
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [4, 5, 1, 22, 25, 6, -1, 8, 10]
}
Test Case 12
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 23, 6, -1, 8, 10]
}
Test Case 13
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 22, 25, 6, -1, 8, 10]
}
Test Case 14
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 22, 6, -1, 8, 10]
}
Test Case 15
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, -1, -1]
}
Test Case 16
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, -1, -1, 10]
}
Test Case 17
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, -1, -2]
}
Test Case 18
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [26]
}
Test Case 19
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 25, 22, 6, -1, 8, 10]
}
Test Case 20
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 26, 22, 8]
}
Test Case 21
{
  "array": [1, 1, 6, 1],
  "sequence": [1, 1, 1, 6]
}
Test Case 22
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, -1, 10, 11, 11, 11, 11]
}
Test Case 23
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 25, 6, -1, 8, 10, 10]
}
Test Case 24
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, -1, 5]
}

Multi String Search

string bigstring = "this is a big string";
string[] smallstrings = { "this", "yo", "is", "a", "bigger", "string", "kappa" };

List result = MultistringSearch(bigstring, smallstrings);
foreach (bool b in result)
{
    Console.WriteLine(b);
}

//Expected output: [true, false, true, true, false, true, false]
      

Solution 1.
public static List MultistringSearch(string bigstring, string[] smallstrings)
{
    List result = new List();
    foreach (string smalString in smallstrings)
    {
        result.Add(isContain(smalString, bigstring));
    }
    return result;
}


public static bool isContain(string smallString, string bigString)
{
    for (int i = 0; i <= bigString.Length - smallString.Length; i++)
    {
        int j;
        for (j = 0; j < smallString.Length; j++)
        {
            if (bigString[i + j] != smallString[j])
            {
                break;
            }
        }
        if (j == smallString.Length)
        {
            return true;
        }
    }
    return false;
}
      

Solution 2:
public static bool IsContain(string smallString, string bigString)
{
    for (int i = 0; i < bigString.Length; i++)
    {
        if (i + smallString.Length > bigString.Length)
        {
            break;
        }

        if(IsContain(smallString, bigString, i))
        {
            return true;
        }
    }
    return false;
}

private static bool IsContain(string smallString, string bigString, int startIdx)
{
    int leftBigidx = startIdx;
    int rightBigIdx = startIdx + smallString.Length - 1;
    int leftSmallIdx = 0;
    int rightSmallIdx = smallString.Length - 1;
    while (leftBigidx <= rightBigIdx)
    {
        if (bigString[leftBigidx] != smallString[leftSmallIdx] ||
                bigString[rightBigIdx] != smallString[rightSmallIdx])
        {
            return false;
        }
        leftBigidx++;
        rightBigIdx--;
        leftSmallIdx++;
        rightSmallIdx--;
    }
    return true;
}

Test case

Test Case 1
{
  "bigString": "this is a big string",
  "smallStrings": ["this", "yo", "is", "a", "bigger", "string", "kappa"]
}

Test Case 2
{
  "bigString": "abcdefghijklmnopqrstuvwxyz",
  "smallStrings": ["abc", "mnopqr", "wyz", "no", "e", "tuuv"]
}

Test Case 3
{
  "bigString": "abcdefghijklmnopqrstuvwxyz",
  "smallStrings": ["abcdefghijklmnopqrstuvwxyz", "abc", "j", "mnopqr", "pqrstuvwxyz", "xyzz", "defh"]
}

Test Case 4
{
  "bigString": "hj!)!%Hj1jh8f1985n!)51",
  "smallStrings": ["%Hj7", "8f198", "!)5", "!)!", "!!", "jh81", "j181hf"]
}

Test Case 5
{
  "bigString": "Mary goes to the shopping center every week.",
  "smallStrings": ["to", "Mary", "centers", "shop", "shopping", "string", "kappa"]
}

Test Case 6
{
  "bigString": "adcb akfkw afnmc fkadn vkaca jdaf dacb cdba cbda",
  "smallStrings": ["abcd", "acbd", "adbc", "dabc", "cbda", "cabd", "cdab"]
}

Test Case 7
{
  "bigString": "test testing testings tests testers test-takers",
  "smallStrings": ["tests", "testatk", "testiing", "trsatii", "test-taker", "test"]
}

Test Case 8
{
  "bigString": "ndbajwhfawkjljkfaopwdlaawjk dawkj awjkawkfjhkawk ahjwkjad jadfljawd",
  "smallStrings": ["abc", "akwbc", "awbc", "abafac", "ajjfbc", "abac", "jadfl"]
}

Test Case 9
{
  "bigString": "Is this particular test going to pass or is it going to fail? That is the question.",
  "smallStrings": ["that", "the", "questions", "goes", "mountain", "passes", "passed", "going", "is"]
}

Test Case 10
{
  "bigString": "Everything in this test should fail.",
  "smallStrings": ["everything", "inn", "that", "testers", "shall", "failure"]
}

Test Case 11
{
  "bigString": "this ain't a big string",
  "smallStrings": ["this", "is", "yo", "a", "bigger"]
}

Test Case 12
{
  "bigString": "bbbabb",
  "smallStrings": ["bbabb"]
}

Two Number Sum

int[] array = { 1, 2, 4, 5, 7, 8, 9, 6 };
int targetSum = 10;
int[] expectedResult = TwoNumberSum_Solution0(array, targetSum);

foreach (int item in expectedResult)
{
	Console.WriteLine(item);
}
      

Solution 1.
public static int[] TwoNumberSum_Solution0(int[] array, int targetSum)
{

    for (int i = 0; i < array.Length - 1; i++)
    {
        int firstNum = array[i];
        for (int j = i + 1; j < array.Length; j++)
        {
            int secondNum = array[j];
            if (firstNum + secondNum == targetSum)
            {
                return new int[] { array[i], array[j] };
            }
        }
    }
    return new int[0];
}
      

Solution 2
//using System.Collections.Generic;

public static int[] TwoNumberSum(int[] array, int targetSum)
{
    HashSet visited = new HashSet();

    foreach (int num in array)
    {
        int expectedResult = targetSum - num;

        if (visited.Contains(expectedResult))
        {
            return new int[] { expectedResult, num };
        }
        else
        {
            visited.Add(num);
        }
    }
    return new int[0];
}

Test case

{
  "array": [4, 5, -4, 8, 12, 1, -2, 6],
  "targetSum": 10
}

{
  "array": [4, 6],
  "targetSum": 10
}

{
  "array": [4, 6, 1],
  "targetSum": 5
}

{
  "array": [4, 6, 1, -3],
  "targetSum": 3
}

{
  "array": [1, 2, 3, 4, 5, 6, 7, 8, 9],
  "targetSum": 17
}

{
  "array": [1, 2, 3, 4, 5, 6, 7, 8, 9, 15],
  "targetSum": 18
}

{
  "array": [-7, -5, -3, -1, 0, 1, 3, 5, 7],
  "targetSum": -5
}

{
  "array": [-21, 301, 12, 4, 65, 56, 210, 356, 9, -47],
  "targetSum": 163
}

{
  "array": [-21, 301, 12, 4, 65, 56, 210, 356, 9, -47],
  "targetSum": 164
}

{
  "array": [3, 5, -4, 8, 11, 1, -1, 6],
  "targetSum": 15
}

{
  "array": [14],
  "targetSum": 15
}

{
  "array": [15],
  "targetSum": 15
}

API Authentication

Reference · Identity & Access API Authentication Methods Four common ways a client proves who it is to a server, ord...

Recent Post