Posts

Showing posts from December, 2024

Data Structures & Algorithms | Top Java HashMap Coding Questions for MAANG Companies

Image
When preparing for coding interviews, especially with top companies like MAANG (Meta, Apple, Amazon, Netflix, Google), it's essential to have a strong grasp of common data structures and algorithms, including HashMap. Below are some common HashMap-related coding problems you might encounter, along with a brief explanation and Java solutions. 1. Two Sum (Using HashMap) Problem: Given an array of integers and a target sum, find two numbers such that they add up to the target. Solution using HashMap: import java.util. HashMap ; public class TwoSum { public int [] twoSum( int [] nums, int target) { HashMap <Integer, Integer> map = new HashMap <>(); for ( int i = 0 ; i < nums.length; i++) { int complement = target - nums[i]; if ( map .containsKey(complement)) { return new int [] { map . get (complement), i }; } map .put(nums[i], i); } throw new IllegalArgume...

Raspberry Pi Device Control: Python Flask Web App for On/Off Automation with Adafruit

Image
To create a Flask web app that controls a device (on/off) using a Raspberry Pi and Adafruit libraries, follow the steps below: Prerequisites Hardware: Raspberry Pi with Raspbian OS installed. Relay module. Device to control (e.g., LED or an AC/DC device via a relay). Jumper wires. Software: Python and Flask installed. Adafruit Blinka library for GPIO control. Steps 1. Install Flask and Adafruit Blinka Run the following commands: sudo apt update sudo apt install python3-pip pip3 install flask adafruit-blinka 2. Wire the Relay to the Raspberry Pi Connect the VCC and GND of the relay to the 5V and GND pins of the Raspberry Pi. Connect the IN pin of the relay to a GPIO pin (e.g., GPIO17). 3. Python Flask Code Create a Flask application to toggle the relay: from flask import Flask, render_template, request import board import digitalio app = Flask(__name__) # Initialize GPIO pin relay_pin = digitalio.DigitalInOut(board.D17) # Replace D17 with your GPIO pin relay_pin.direction...

How to Integrate Azure OpenAI Service with ASP.NET Core Web API

Image
Integrating Azure OpenAI Service with an ASP.NET application allows you to build web-based solutions powered by OpenAI's GPT models (like GPT-3 or GPT-4) using Azure’s API. Below is an end-to-end guide on how to build an ASP.NET Core Web API application that interacts with the Azure OpenAI Service. Prerequisites Azure Subscription : You need an Azure account to create an OpenAI resource. Azure OpenAI Resource : Create an OpenAI resource in Azure and get your API key and endpoint . .NET SDK : Install the .NET SDK . NuGet Packages : You’ll need the following NuGet packages: Microsoft.Extensions.Configuration Newtonsoft.Json Microsoft.AspNetCore.Mvc.NewtonsoftJson Step 1: Create an ASP.NET Core Web API Project Create a new ASP.NET Core Web API project: dotnet new webapi -n AzureOpenAIServiceApi cd AzureOpenAIServiceApi Step 2: Install NuGet Packages Install the necessary NuGet packages: dotnet add package Newtonsoft .Json dotnet add package Microsoft .Extensions .Configuration ...

Spring AI PDF Document Reader: Extract Text with Apache PDFBox in Spring Boot

Image
To use the Spring AI PDF Document Reader , which utilizes Apache PDFBox to extract text from PDF documents in a Spring Boot application, you can follow this comprehensive example. Steps to Implement 1. Setup Spring Boot Application Make sure you have a Spring Boot project with the necessary dependencies. You can generate a Spring Boot project using  Spring Initializr . Dependencies: Spring Web  for creating REST endpoints. PDF Document Reader  Spring AI PDF document reader. It uses Apache PdfBox to extract text from PDF documents and converting them into a list of Spring AI Document objects.. Complete  pom.xml <? xml version= "1.0" encoding= "UTF-8" ?> < project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion > 4.0.0 </ modelVersion >...

How to integrate Neo4j with Spring Boot for storing and querying graph data

Image
To set up a simple Spring Boot project with Spring Data Neo4j, follow the steps below. This example demonstrates how to integrate Neo4j with Spring Boot for storing and querying graph data. 1. Set up the Project Using Spring Initializr: You can create a Spring Boot project using Spring Initializr with the following options: Project : Maven Language : Java Spring Boot version : 3.4.1 (or the latest 3.x version available) Dependencies : Spring Data Neo4j Spring Web Neo4j Driver (this should be automatically included with spring-boot-starter-data-neo4j ) Alternatively, you can manually set up the Maven pom.xml for your Spring Boot project. 2. Add Dependencies to pom.xml Add the following dependencies for Spring Boot 3.4.1 and Spring Data Neo4j. < dependencies > <!-- Spring Boot and Spring Data Neo4j dependencies --> < dependency > < groupId > org.springframework.boot </ groupId > < artifactId > spring-boot-starter-data-neo4...

Java OOPS: Interview Preparation Guide for Freshers

Image
Here's a comprehensive guide to preparing for Java interviews with a focus on Object-Oriented Programming System (OOPS) concepts: OOPS Theory Four Pillars of OOPS Encapsulation Definition : Wrapping data (variables) and methods (functions) together as a single unit. Practical Use : Access modifiers like private , protected , and public to restrict direct access to class fields. Example : public class Employee { private String name ; private int age; public String getName() { return name ; } public void setName(String name ) { this. name = name ; } } Inheritance Definition : A mechanism where one class acquires the properties and behaviors of a parent class. Types : Single, Multilevel, Hierarchical. Example : public class Animal { void eat() { System .out.println( "This animal eats food." ); } } public class Dog extends Animal { void bark() { System .out.println( "This dog b...