question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
number-of-restricted-paths-from-first-to-last-node | C++ Graph :Dijikstra + DP Based Well Commented Solution | c-graph-dijikstra-dp-based-well-commente-ncjv | IntuitionStep1: find dist of all nodes from n
Step2 : Using DP find all paths such that : distanceToLastNode(zi) > distanceToLastNode(zi+1).....Complexity
Time | SJ4u | NORMAL | 2025-04-04T20:01:40.912693+00:00 | 2025-04-04T20:01:40.912693+00:00 | 3 | false | # Intuition
Step1: find dist of all nodes from n
Step2 : Using DP find all paths such that : distanceToLastNode(zi) > distanceToLastNode(zi+1).....
# Complexity
- Time complexity: $$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: $$O(n)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```cpp []
#define p pair<int,int>
#define mod 1000000007
class Solution {
public:
int dp[20001];
int recurs(unordered_map<int,vector<p>>&graph,vector<int>&dist, int n,int node){
if(node == n)
return 1;
if(dp[node]!=-1)
return dp[node];
int ans = 0;
for(auto x:graph[node]){
int node_x = x.first;
if(dist[node_x]<dist[node]){ //distanceToLastNode(zi) > distanceToLastNode(zi+1)
ans+=recurs(graph,dist,n,node_x)%mod;
ans%=mod;
}
}
return dp[node]=ans;
}
int countRestrictedPaths(int n, vector<vector<int>>& edges) {
memset(dp,-1,sizeof(dp));
vector<int>dist(n+1,INT_MAX);
unordered_map<int,vector<p>>graph;
priority_queue<p,vector<p>,greater<p>>pq;
int ans = 0;
dist[n] = 0;
pq.push({0,n});
for(auto x:edges){ // graph construction
graph[x[0]].push_back({x[1],x[2]});
graph[x[1]].push_back({x[0],x[2]});
}
// STEP 1:
// fetching shortest distance from n->to all other nodes
while(pq.size()){
int node = pq.top().second;
int distance = pq.top().first;
pq.pop();
for(auto x:graph[node]){
int node_x = x.first, dist_x = x.second;
if(dist[node_x] > (distance+dist_x)){ // we have found some shorter path to reach here than prev.
dist[node_x] = (distance+dist_x);
pq.push({dist[node_x],node_x});
}
}
}
// STEP 2:
ans = recurs(graph,dist,n,1);
return ans;
}
};
``` | 0 | 0 | ['C++'] | 0 |
number-of-restricted-paths-from-first-to-last-node | Dijkstra's | DP | DFS | dijkstras-dp-dfs-by-_navjot_singh_1-5jn6 | Code | _navjot_singh_1 | NORMAL | 2025-03-27T12:35:35.314175+00:00 | 2025-03-27T12:35:35.314175+00:00 | 6 | false |
# Code
```cpp []
class Solution {
public:
const int mod = 1e9 + 7;
vector<int> smallest(vector<vector<pair<int,int>>> &adj, int n, int src){
// distance node
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > pq;
vector<int> dist(n+1,INT_MAX);
dist[src] = 0;
pq.push({0,src});
while(!pq.empty()){
int w = pq.top().first, u = pq.top().second;
pq.pop();
for(auto it : adj[u]){
int v = it.first, wt = it.second;
int cost = wt + w;
if(dist[v] > cost){
dist[v] = cost;
pq.push({cost,v});
}
}
}
return dist;
}
int dfs(int node, int n, vector<vector<pair<int,int>>> &adj,vector<int> &dist,vector<int> &dp){
if(node == n) return 1;
if(dp[node] != -1) return dp[node];
int count = 0;
for(auto it : adj[node]){
int v = it.first, w = it.second;
if(dist[node] > dist[v] ){
count = (count + dfs(v,n,adj,dist,dp))%mod;
}
}
return dp[node] = count;
}
int countRestrictedPaths(int n, vector<vector<int>>& edges) {
vector<vector<pair<int,int>>> adj(n+1);
for(auto it : edges){
int u = it[0], v = it[1], wt = it[2];
adj[u].push_back({v,wt});
adj[v].push_back({u,wt});
}
vector<int> dist = smallest(adj,n,n);
vector<int> dp(n+1,-1);
int ans = dfs(1,n,adj,dist,dp);
return ans;
}
};
``` | 0 | 0 | ['C++'] | 0 |
number-of-restricted-paths-from-first-to-last-node | Python3 - Dijkstra + Memoization | python3-dijkstra-memoization-by-npthao-wvl8 | Code | npthao | NORMAL | 2025-03-10T18:42:23.219090+00:00 | 2025-03-10T18:42:23.219090+00:00 | 9 | false | # Code
```python3 []
class Solution:
def countRestrictedPaths(self, n: int, edges: List[List[int]]) -> int:
graph = defaultdict(list)
for u,v,w in edges:
graph[u].append((v,w))
graph[v].append((u,w))
def dijkstra(start, graph):
dist = {i : float('inf') for i in range(1,n+1)}
dist[start] = 0
pq = [(0, start)]
while pq:
dis, node = heapq.heappop(pq)
if dis > dist[node]:
continue
for nei, w in graph[node]:
new_dis = dis + w
if new_dis < dist[nei]:
dist[nei] = new_dis
heapq.heappush(pq, (new_dis, nei))
return dist
shortest_path = dijkstra(n, graph)
count = 0
MOD = 10**9 + 7
memo = {}
def dfs(node):
if node == n:
return 1
if node in memo:
return memo[node]
cnt = 0
for nei, _ in graph[node]:
if shortest_path[node] > shortest_path[nei]:
cnt = (cnt + dfs(nei)) % MOD
memo[node] = cnt
return memo[node]
return dfs(1)
``` | 0 | 0 | ['Python3'] | 0 |
number-of-restricted-paths-from-first-to-last-node | Python3 - Dijkstra + DP | python3-dijkstra-dp-by-npthao-2dt8 | Code | npthao | NORMAL | 2025-03-10T18:40:42.902777+00:00 | 2025-03-10T18:40:55.043377+00:00 | 6 | false | # Code
```python3 []
class Solution:
def countRestrictedPaths(self, n: int, edges: List[List[int]]) -> int:
graph = defaultdict(list)
for u,v,w in edges:
graph[u].append((v,w))
graph[v].append((u,w))
dist = [float('inf')]*(n+1) #Dijkstra array to store shortest path
dist[n] = 0
MOD = 10**9 + 7
dp = [0]*(n+1)
dp[n] = 1 #base case: 1 way for last node to itself
#update from last node -> 1
pq = [(0, n)]
while pq:
dis, node = heapq.heappop(pq)
if dis > dist[node]:
continue
for nei, w in graph[node]:
new_dis = dis + w
if new_dis < dist[nei]:
dist[nei] = new_dis
heapq.heappush(pq, (new_dis, nei))
#current path distance > shortest path to neighbor, update dp
elif dis > dist[nei]:
dp[node] = (dp[node] + dp[nei]) % MOD
if node == 1:
break
return dp[1]
``` | 0 | 0 | ['Python3'] | 0 |
number-of-restricted-paths-from-first-to-last-node | ✅Dijkstra's Algorithm + Linear DP | dijkstras-algorithm-linear-dp-by-akash_s-0oda | IntuitionThe problem ask's to find all restricted paths such that every node in the path follows condition i.e distanceToLastNode(currNode) > distanceToLastNode | Akash_Sonar | NORMAL | 2025-02-28T11:48:13.102666+00:00 | 2025-02-28T11:48:13.102666+00:00 | 7 | false | # Intuition
The problem ask's to find all restricted paths such that every node in the path follows condition i.e `distanceToLastNode(currNode) > distanceToLastNode(nextNode)`
The very frist thing we need is the min dist from every node to n. If we apply Dijkstra's Algorithm for shorest path from every node to n, it will be not feasible, since Dijkstra's Algorithm takes `O((V+E)logV) `to find the min dist,, so for all nodes it will be `O(V(V+E)logV) `.
To make it efficient, we will find shorest path from n to any node let's say 1. In the process of finding shorest path from `n to 1`, the algorithm also finds shorest path from n to every other node.
NOW WE HAVE THE DISTANCE ARRAY WITH US.
The next thing we wanna do is to find all the restricted path from 1 to n. The brute force way would be to, first find all the paths from 1 to n and then for every path check the condition if it holds true.
It will obviously result in TLE, we wanna do better than this.
We realize that there are many subproblem in finding paths from 1 to n
i.e `1->3->4->6->10` , `1->8->2->4->6->10`, `1->3->7->9->4->6->10` ....
This give us hint (and even the constrain's) that some dp can be applied.
Let's define dp, `dp[i] = no. of paths from i to 1`, satisfying the condition i.e `distanceToLastNode(currNode) < distanceToLastNode(prevNode)`
**NOTE : we have used reverse condition, since we will be going in backward direction in the path and check if it reachs to 1, if yes return 1 (indicating path is found) else 0 (No path found, which reaches to 1).**
# Approach
1. Find shortest path from n to every other nodes using Dijkstra's Algorithm.
2. Starting from n traverse backward and check how many paths reaches to 1.
3. Use dp to avoid unneccessary computation, if curr node is already visited.
# Complexity
- Time complexity:
O((V+E)logV) + O(V)
- Space complexity:
O(V)
# Code
```java []
class Solution {
private final int MOD = 1_000_000_007;
private int dp[];
public int countRestrictedPaths(int n, int[][] edges) {
List<int[]> g[] = new ArrayList[n];
for(int i=0; i<n; i++) g[i] = new ArrayList<>();
for(int e[] : edges){
g[e[0]-1].add(new int[]{e[1]-1, e[2]});
g[e[1]-1].add(new int[]{e[0]-1, e[2]});
}
int dist[] = dijkstrasAlgo(g); // Now i have min dist from every node to n.
// Now for every path from from 1 -> n check if it is a restricted path.
/* dp[i] = no. of paths from i to 1, which satisfies the condition
i.e distanceToLastNode[z] < distanceToLastNode[prevZ] */
// so i must reach to 1 from n, reverse order
this.dp = new int[n];
Arrays.fill(dp, -1);
return findPaths(n-1, g, dist);
}
private int findPaths(int curr, List<int[]> g[], int dist[]){
if(curr == 0){
return 1;
}
if(dp[curr] != -1) return dp[curr];
int res = 0;
for(int nbr[] : g[curr]){
if(dist[curr] < dist[nbr[0]]){
res = (res + findPaths(nbr[0], g, dist) % MOD) % MOD;
}
}
return dp[curr] = res;
}
private int[] dijkstrasAlgo(List<int[]> g[]){
int m = g.length;
int dist[] = new int[m];
Arrays.fill(dist, Integer.MAX_VALUE);
dist[m-1] = 0;
boolean vis[] = new boolean[m];
PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> Integer.compare(a[1], b[1]));
pq.offer(new int[]{m-1, 0});
while(!pq.isEmpty()){
int curr[] = pq.poll();
if(!vis[curr[0]]){
vis[curr[0]] = true;
for(int nbr[] : g[curr[0]]){
int nbrCost = nbr[1] + curr[1];
if(nbrCost < dist[nbr[0]]){
dist[nbr[0]] = nbrCost;
pq.offer(new int[]{nbr[0], nbrCost});
}
}
}
}
return dist;
}
}
``` | 0 | 0 | ['Dynamic Programming', 'Shortest Path', 'Java'] | 0 |
number-of-restricted-paths-from-first-to-last-node | Go - Djikstra + Dynamic Programming | go-djikstra-dynamic-programming-by-aaron-7q8s | Code | aaron_mathis | NORMAL | 2025-02-26T17:37:35.893946+00:00 | 2025-02-26T17:37:35.893946+00:00 | 9 | false | # Code
```golang []
package main
import (
"container/heap"
"fmt"
"math"
"sort"
)
const MOD = 1_000_000_007
// PriorityQueue implements a min-heap
type PriorityQueue []Node
type Node struct {
dist int
id int
}
func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool { return pq[i].dist < pq[j].dist }
func (pq PriorityQueue) Swap(i, j int) { pq[i], pq[j] = pq[j], pq[i] }
func (pq *PriorityQueue) Push(x interface{}) { *pq = append(*pq, x.(Node)) }
func (pq *PriorityQueue) Pop() interface{} {
old := *pq
n := len(old)
item := old[n-1]
*pq = old[:n-1]
return item
}
func countRestrictedPaths(n int, edges [][]int) int {
graph := make(map[int][][]int)
for i := 1; i <= n; i++ {
graph[i] = [][]int{}
}
for _, edge := range edges {
u, v, weight := edge[0], edge[1], edge[2]
graph[u] = append(graph[u], []int{weight, v})
graph[v] = append(graph[v], []int{weight, u})
}
distance := make([]int, n+1)
for i := range distance {
distance[i] = math.MaxInt64
}
distance[n] = 0
pq := &PriorityQueue{}
heap.Init(pq)
heap.Push(pq, Node{dist: 0, id: n})
for pq.Len() > 0 {
curr := heap.Pop(pq).(Node)
node, weight := curr.id, curr.dist
if weight > distance[node] {
continue
}
for _, neighbor := range graph[node] {
nweight, nnode := neighbor[0], neighbor[1]
newWeight := weight + nweight
if newWeight < distance[nnode] {
distance[nnode] = newWeight
heap.Push(pq, Node{dist: newWeight, id: nnode})
}
}
}
dp := make([]int, n+1)
dp[n] = 1
nodes := make([]int, n)
for i := 1; i <= n; i++ {
nodes[i-1] = i
}
sort.Slice(nodes, func(i, j int) bool {
return distance[nodes[i]] < distance[nodes[j]]
})
for _, node := range nodes {
if node == n {
continue
}
for _, neighbor := range graph[node] {
nnode := neighbor[1]
if distance[node] > distance[nnode] { // Only count valid restricted paths
dp[node] = (dp[node] + dp[nnode]) % MOD
}
}
}
return dp[1]
}
``` | 0 | 0 | ['Dynamic Programming', 'Graph', 'Topological Sort', 'Heap (Priority Queue)', 'Shortest Path', 'Go'] | 0 |
number-of-restricted-paths-from-first-to-last-node | Python3 - Beats 100%- Dijkstra's algorithm + Dynamic Programming (BFS, heap, memoization) | python3-beats-100-dijkstras-algorithm-dy-rtpv | IntuitionThis problem will require finding the shortest path from the end node to all other nodes. To do this, we will use Dijkstra's algorithm (BFS + Priority | aaron_mathis | NORMAL | 2025-02-26T17:27:20.532634+00:00 | 2025-02-26T17:27:20.532634+00:00 | 8 | false | # Intuition
This problem will require finding the shortest path from the end node to all other nodes. To do this, we will use Dijkstra's algorithm (BFS + Priority Queue).
At that point, we can simply use dynamic programming to figure out the number of paths from 1 - n that meet the restricted condition.
To be extremely efficient, we can do this memoization during the BFS traversal.
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
1. Set `MOD` to $$10^9 + 7$$
2. Build undirected graph using a dictionary containing lists by iterating through edges, appending a tuple of `(weight, destination node)` to the list for key `source node`. Since it is undirected, add an entry to `u` for `v` and `v` for `u`.
3. Initialize distance array of size `n+1` set to positive infinity and set `distance[n]` to `0` (since we are finding distance FROM `n`)
4. Initialize `dp` as an array for memoization/DP to track number of paths from `i` to `n`
5. Initialize priority queue that holds `(current weight, node)`
6. Process priority queue, every iteration:
- Pop node and current weight with smallest weight (dijkstra's)
- Skip if current weight is greater than distance noted in `distance[node]`.
- Process `node`'s neighbors in the graph.
- If neighbor's weight + distance recorded for node is less than distance recorded for neighboring node, mark `distance[nnode]` with that weight and push the neighboring node into the min-heap.
- Else, if current node's path weight is greater than distance recorded for neighbor node, set `dp[node]` equal to `dp[node] + dp[nnode] % MOD`.
- If you've reached node 1, break the loop
7. Return `dp[1]`, as this will return the number of restricted paths to `n`
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity: $$O((V+E)logV)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: $$ O(V+E) $$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```python3 []
class Solution:
def countRestrictedPaths(self, n: int, edges: List[List[int]]) -> int:
MOD = 10**9 + 7 # Return MOD of answer
# Build Undirected Graph where graph[node_a] -> (weight, node_b) shows a connection
graph = {x:[] for x in range(1, n+1)}
for u, v, weight in edges:
graph[u].append((weight, v))
graph[v].append((weight, u))
# Distance array to track shortest distance from starting node to node at index i
distance = [inf] * (n+1)
distance[n] = 0
# DP array for Memoization of number of paths from 1-n
dp = [0] * (n+1)
dp[n] = 1
# Combine Dijkstra's formula (min heap + BFS) with DP
pq = [(0, n)] # Priority Queue (min-heap) for BFS
# Process pq
while pq:
# Get the node with the smallest distance
weight, node = heappop(pq)
# If the current path is longer than already known path to node, move on
if weight > distance[node]:
continue
# Process next node's, updating the distance to next node if smaller than currently known paths.
# If a shorter path is found, add the next node to min-heap/pq to process further.
# If current path distance is greater than shortest path to neighbor, update dp table
for nweight, nnode in graph[node]:
new_weight = nweight + distance[node]
if new_weight < distance[nnode]:
distance[nnode] = new_weight
heappush(pq, (new_weight, nnode))
elif weight > distance[nnode]:
dp[node] = (dp[node] + dp[nnode]) % MOD
if node == 1:
break
return dp[1]
``` | 0 | 0 | ['Dynamic Programming', 'Graph', 'Heap (Priority Queue)', 'Shortest Path', 'Python3'] | 0 |
number-of-restricted-paths-from-first-to-last-node | Very Easy Check Once | very-easy-check-once-by-aniketb11-bsy4 | IntuitionThe problem requires counting paths from node1to noden, with the restriction that each step must move to a node with a strictly smaller shortest distan | aniketb11 | NORMAL | 2025-02-19T18:37:39.439028+00:00 | 2025-02-19T18:37:39.439028+00:00 | 7 | false | ## **Intuition**
The problem requires counting paths from node **1** to node **n**, with the restriction that each step must move to a node with a strictly smaller shortest distance to node **n**.
1. First, compute the shortest path from **n** to all other nodes using **Dijkstra’s Algorithm**.
2. Then, use **DFS with memoization** to count the valid paths from **1** to **n**, ensuring that we only move to nodes with a strictly larger shortest path distance.
---
## **Approach**
1. **Graph Representation**
- Use an **adjacency list** where `adj[i]` stores `(neighbor, weight)` pairs for each node `i`.
2. **Dijkstra’s Algorithm**
- Initialize an array `dist[]` to store the shortest distance from **node n** to all other nodes.
- Use a **min-heap (priority queue)** to process nodes based on increasing distance.
- Relax edges to compute shortest paths.
3. **DFS with Memoization**
- Define a recursive function `a(adj, dist, dp, node)`, where:
- `adj` stores the graph.
- `dist` contains the shortest distances from `n` to all nodes.
- `dp[i]` memoizes the count of valid paths from `i` to `n`.
- Start DFS from node **1**.
- At each node, iterate over its neighbors and move only if `dist[neighbor] > dist[current]`.
- Return the total number of valid paths modulo **10⁹ + 7**.
---
## **Complexity Analysis**
- **Dijkstra’s Algorithm**:
- Uses a **priority queue** (min-heap), leading to **O((E + V) log V)** time complexity.
- **DFS with Memoization**:
- Each node is visited once in the worst case, giving **O(V + E)** time complexity.
- **Overall Complexity**:
- **O((E + V) log V) + O(V + E) ≈ O((E + V) log V)**.
- **Space Complexity**:
- **O(V + E)** for adjacency list.
- **O(V)** for `dist[]` and `dp[]`.
- **O(V)** recursion depth in the worst case.
- **Total: O(V + E)**.
# Code
```java []
class Solution {
public int countRestrictedPaths(int n, int[][] edges) {
List<List<int[]>> adj=new ArrayList<>();
for(int i=0;i<=n;i++)adj.add(new ArrayList<>());
for(int[]a:edges){
adj.get(a[0]).add(new int[]{a[1],a[2]});
adj.get(a[1]).add(new int[]{a[0],a[2]});
}
int[]dist=new int[n+1];
Arrays.fill(dist,Integer.MAX_VALUE);
dist[n]=0;
PriorityQueue<int[]> pq=new PriorityQueue<>((a,b)->a[1]-b[1]);
pq.add(new int[]{n,0});
while(!pq.isEmpty()){
int[]curr=pq.poll();
if(curr[1]>dist[curr[0]])continue;
for(int[]a:adj.get(curr[0])){
if(curr[1]+a[1]<dist[a[0]]){
dist[a[0]]=curr[1]+a[1];
pq.add(new int[]{a[0],dist[a[0]]});
}
}
}
int[]dp=new int[n+1];
Arrays.fill(dp,-1);
return a(adj,dist,dp,n);
}
public int a(List<List<int[]>> adj,int[]dist,int[]dp,int n){
if(n==1)return 1;
if(dp[n]!=-1)return dp[n];
int c=0;
for(int[]a:adj.get(n)){
if(dist[a[0]]>dist[n]){
c=(c+a(adj,dist,dp,a[0]))%1000000007;
}
}
return dp[n]=c;
}
}
``` | 0 | 0 | ['Dynamic Programming', 'Graph', 'Topological Sort', 'Heap (Priority Queue)', 'Shortest Path', 'Java'] | 0 |
number-of-restricted-paths-from-first-to-last-node | C++ solution | c-solution-by-36zpt9pafz-8f1k | Code | 36ZPt9PAFz | NORMAL | 2025-02-02T15:10:29.874975+00:00 | 2025-02-02T15:10:29.874975+00:00 | 5 | false |
# Code
```cpp []
class Solution {
public:
int countRestrictedPaths(int n, vector<vector<int>>& edges) {
const unsigned int M = 1000000007;
vector<vector<pair<int, int>>> adj(n + 1);
// create adjacent matrix
for (vector<int>& e : edges) {
adj[e[0]].push_back({e[1], e[2]});
adj[e[1]].push_back({e[0], e[2]});
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
vector<bool> vis(n + 1, 0);
// minDist[i] means the length of the shortest path from node i to last node
vector<int> minDist(n + 1, INT_MAX);
// numRestricted[i] means the number of restricted paths from node i to last node.
vector<int> numRestricted(n + 1, 0);
pq.push({0, n});
minDist[n] = 0;
numRestricted[n] = 1;
while (!pq.empty()) {
int currDist = pq.top().first;
int currNode = pq.top().second;
pq.pop();
if (vis[currNode]) continue;
vis[currNode] = 1;
for (auto& pair : adj[currNode]) {
int adjNode = pair.first;
int adjDist = pair.second;
if (adjDist + currDist < minDist[adjNode]) {
minDist[adjNode] = adjDist + currDist;
pq.push({adjDist + currDist, adjNode});
}
if (minDist[adjNode] > currDist)
numRestricted[adjNode] = ((long long) numRestricted[adjNode] + numRestricted[currNode]) % M;
}
}
return numRestricted[1];
}
};
``` | 0 | 0 | ['Heap (Priority Queue)', 'Shortest Path', 'C++'] | 0 |
number-of-restricted-paths-from-first-to-last-node | Easy C++ solution Dijkstra's algorithm and DFS | easy-c-solution-dijkstras-algorithm-and-zs5wj | Please upvote if you have got any help from my code. Thank you. | imran2018wahid | NORMAL | 2025-02-01T19:09:00.515221+00:00 | 2025-02-01T19:09:00.515221+00:00 | 9 | false | ```
typedef pair<int, int> p;
class Solution {
public:
int mod = 1e9+7;
int dfs(vector<vector<int>> adj[], vector<int>&dis, int curr, int n, vector<int>&dp) {
if (curr == n) {
return dp[curr] = 1;
}
if (dp[curr] != -1) {
return dp[curr];
}
int count = 0;
for (auto neighbour : adj[curr]) {
if (dis[curr] > dis[neighbour[0]]) {
if (dp[neighbour[0]] == -1) {
dp[neighbour[0]] = dfs(adj, dis, neighbour[0], n, dp);
}
count = (count + dp[neighbour[0]])%mod;
}
}
return dp[curr] = count;
}
int countRestrictedPaths(int n, vector<vector<int>>& edges) {
vector<vector<int>> adj[n+1];
for (vector<int> edge : edges) {
adj[edge[0]].push_back({edge[1], edge[2]});
adj[edge[1]].push_back({edge[0], edge[2]});
}
priority_queue<p, vector<p>, greater<p>> q;
vector<int>dis(n+1, INT_MAX);
dis[n] = 0;
q.push(make_pair(0, n));
while (!q.empty()) {
p current = q.top();
q.pop();
for (auto neighbour : adj[current.second]) {
int edgeWeight = neighbour[1], node = neighbour[0];
if ((edgeWeight+current.first) < dis[node]) {
dis[node] = edgeWeight+current.first;
q.push(make_pair(dis[node], node));
}
}
}
vector<int>dp(n+1, -1);
return dfs(adj, dis, 1, n, dp);
}
};
```
***Please upvote if you have got any help from my code. Thank you.*** | 0 | 0 | ['C++'] | 0 |
number-of-restricted-paths-from-first-to-last-node | 1786. Number of Restricted Paths From First to Last Node | 1786-number-of-restricted-paths-from-fir-9e1v | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-15T03:27:01.592280+00:00 | 2025-01-15T03:27:01.592280+00:00 | 9 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```python3 []
import heapq
from collections import defaultdict
MOD = 10**9 + 7
class Solution:
def countRestrictedPaths(self, n, edges):
if n == 1:
return 0
graph = defaultdict(list)
for u, v, w in edges:
graph[u].append((w, v))
graph[v].append((w, u))
dist = [float('inf')] * (n + 1)
dist[n] = 0
pq = [(0, n)]
while pq:
d, node = heapq.heappop(pq)
if dist[node] < d:
continue
for weight, neighbor in graph[node]:
if dist[neighbor] > dist[node] + weight:
dist[neighbor] = dist[node] + weight
heapq.heappush(pq, (dist[neighbor], neighbor))
dp = [-1] * (n + 1)
def find_paths(node):
if node == n:
return 1
if dp[node] != -1:
return dp[node]
path_count = 0
for _, neighbor in graph[node]:
if dist[node] > dist[neighbor]:
path_count = (path_count + find_paths(neighbor)) % MOD
dp[node] = path_count
return path_count
return find_paths(1)
``` | 0 | 0 | ['Python3'] | 0 |
number-of-restricted-paths-from-first-to-last-node | Djikstras && DFS till test case 43/77 then Djikstras dfs +DP to pass all | djikstras-dfs-till-test-case-4377-then-d-stmk | Intuitionusing Dijkstras && DFS
we only reach till testcase 42/77 or sowe need dp after that
1 submistion is without dp fail for test case n=422
2 submition is | yui_ishigami | NORMAL | 2025-01-07T14:26:40.318238+00:00 | 2025-01-07T14:26:40.318238+00:00 | 8 | false | # Intuition
using Dijkstras && DFS
we only reach till testcase 42/77 or so
we need dp after that
1 submistion is without dp fail for test case n=422
2 submition is dp pass all the test case
# Code
```java []
// 1 solution submition is tle for 422
class store {
int dist;
int node;
public store(int dist, int node) {
this.dist = dist;
this.node = node;
}
}
class adj_stru {
int u;
int v;
int wt;
public adj_stru(int u, int v, int wt) {
this.u = u;
this.v = v;
this.wt = wt;
}
}
class Solution {
public int countRestrictedPaths(int n, int[][] mat) {
// convert the mat to adj
ArrayList<ArrayList<adj_stru>> adj = new ArrayList<>();
for (int i = 0; i <= n; i++) {
adj.add(new ArrayList<>());
}
int i=0;
// Fix: Loop correctly over mat[i]
for (int[] edge : mat) {
int u =edge[0];
int v = edge[1];
int wt = edge[2];
adj.get(u).add(new adj_stru(u, v, wt));
adj.get(v).add(new adj_stru(v, u, wt));
}
// Dijkstra's algorithm
PriorityQueue<store> queue = new PriorityQueue<>((a, b) -> a.dist - b.dist);
int[] dist = new int[n+1];
Arrays.fill(dist,Integer.MAX_VALUE);
dist[n] = 0;
int[] visit = new int[n+1]; // Fix: Declare visit array here
Arrays.fill(visit, 0);
queue.add(new store(0, n)); // Starting node with dist 0
while (!queue.isEmpty()) {
store curr = queue.poll();
int node = curr.node;
int distNode = curr.dist; // Use a different variable name to avoid confusion
for (adj_stru ele : adj.get(node)) {
int v = ele.v;
int wt = ele.wt;
int cal_dist = distNode + wt;
if (cal_dist < dist[v]) {
dist[v] = cal_dist;
queue.add(new store(cal_dist, v));
}
}
}
// DFS setup
ArrayList<ArrayList<Integer>> ans = new ArrayList<>();
ArrayList<Integer> vec = new ArrayList<>();
// Start DFS from node 1
dfs(n,1, ans, vec, adj, dist, visit);
return ans.size();
}
public void dfs(int n,int node, ArrayList<ArrayList<Integer>> ans, ArrayList<Integer> vec, ArrayList<ArrayList<adj_stru>> adj, int[] dist, int[] visit) {
visit[node] = 1;
vec.add(node);
if(node==n)
{
System.out.println(vec);
ans.add(new ArrayList<>(vec)); // Add the current path to the answer list
}
else {
for (adj_stru ele : adj.get(node)) {
int neighborNode = ele.v;
int neighborDist = ele.wt;
// Check for restricted path (you might want to use dist[] here)
if (dist[neighborNode] < dist[node]) {
dfs(n,neighborNode, ans, vec, adj, dist, visit);
}
}
}
visit[node] = 0; // Unmark the node after finishing the DFS on it
vec.remove(vec.size() - 1); // Backtrack
}
}
################################################################################
// this optimaztion using dp
// 2 solution
class Solution {
private static final int MOD = 1000000007;
public int countRestrictedPaths(int n, int[][] edges) {
// Build adjacency list using a more efficient structure
List<int[]>[] adj = new List[n + 1];
for (int i = 0; i <= n; i++) {
adj[i] = new ArrayList<>();
}
// Populate adjacency list more efficiently
for (int[] edge : edges) {
int u = edge[0], v = edge[1], w = edge[2];
adj[u].add(new int[]{v, w});
adj[v].add(new int[]{u, w});
}
// Dijkstra with optimizations
int[] dist = new int[n + 1];
Arrays.fill(dist, Integer.MAX_VALUE);
dist[n] = 0;
PriorityQueue<long[]> pq = new PriorityQueue<>((a, b) -> Long.compare(a[1], b[1]));
pq.offer(new long[]{n, 0});
while (!pq.isEmpty()) {
long[] curr = pq.poll();
int node = (int) curr[0];
long d = curr[1];
if (d > dist[node]) continue;
for (int[] next : adj[node]) {
int nextNode = next[0];
int weight = next[1];
if (dist[nextNode] > d + weight) {
dist[nextNode] = (int)(d + weight);
pq.offer(new long[]{nextNode, d + weight});
}
}
}
// Use DP array for memoization
Integer[] memo = new Integer[n + 1];
return dfs(1, n, adj, dist, memo);
}
private int dfs(int node, int n, List<int[]>[] adj, int[] dist, Integer[] memo) {
if (node == n) return 1;
if (memo[node] != null) return memo[node];
long count = 0;
for (int[] next : adj[node]) {
int nextNode = next[0];
if (dist[nextNode] < dist[node]) {
count = (count + dfs(nextNode, n, adj, dist, memo)) % MOD;
}
}
memo[node] = (int) count;
return memo[node];
}
}
``` | 0 | 0 | ['Depth-First Search', 'Graph', 'Java'] | 0 |
number-of-restricted-paths-from-first-to-last-node | PriorityQueue | priorityqueue-by-linda2024-7lxn | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | linda2024 | NORMAL | 2024-12-18T21:18:52.659106+00:00 | 2024-12-18T21:18:52.659106+00:00 | 5 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```csharp []\npublic class Solution {\n private int mod = 1000000007;\n public class Pair\n\t{\n\t\tpublic int node;\n\t\tpublic int weight;\n\t\tpublic Pair(int curNode, int w)\n\t\t{\n\t\t\tnode = curNode;\n\t\t\tweight = w;\n\t\t}\n\t}\n\n\tpublic class PairComp : IComparer<Pair>\n\t{\n\t\tpublic int Compare(Pair x, Pair y)\n\t\t{\n\t\t\treturn x.weight.CompareTo(y.weight);\n\t\t}\n\t}\n\n public int CountRestrictedPaths(int n, int[][] edges) {\n \t\t\t// Init and define adj array:\n\t\t\tHashSet<Pair>[] adj = new HashSet<Pair>[n+1];\n\t\t\tfor (int i = 0; i <= n; i++)\n\t\t\t{\n\t\t\t\tadj[i] = new HashSet<Pair>();\n\t\t\t}\n\n\t\t\tforeach (int[] edge in edges)\n\t\t\t{\n\t\t\t\tint u = edge[0], v = edge[1], w = edge[2];\n\t\t\t\tadj[u].Add(new Pair(v, w));\n\t\t\t\tadj[v].Add(new Pair(u, w));\n\t\t\t}\n\n\t\t\tint[] dist = Enumerable.Repeat(int.MaxValue, n+1).ToArray();\n\t\t\tlong[] res = new long[n+1];\n dist[n] = 0;\n res[n] = 1;\n\t\t\tPriorityQueue<int, int> pq = new PriorityQueue<int, int>();\n\t\t\tpq.Enqueue(n, 0);\n\n\t\t\twhile (pq.TryDequeue(out int node, out int weight))\n\t\t\t{ \n\t\t\t\tif (weight > dist[node])\n\t\t\t\t\tcontinue;\n\n\t\t\t\tif (node == 1)\n break;\n\t\t\t\n\t\t\t\tforeach (Pair neighbor in adj[node])\n\t\t\t\t{ \n\t\t\t\t\tint nextW = neighbor.weight, nextNode = neighbor.node;\n\t\t\t\t\tif (dist[nextNode] > (dist[node] + nextW))\n\t\t\t\t\t{\n\t\t\t\t\t\tdist[nextNode] = (dist[node] + nextW);\n\t\t\t\t\t\tpq.Enqueue(nextNode, dist[nextNode]);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (dist[nextNode] > dist[node])\n\t\t\t\t\t{\n\t\t\t\t\t\tres[nextNode] += res[node];\n\t\t\t\t\t\tres[nextNode] %= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn (int)res[1];\n\n }\n}\n``` | 0 | 0 | ['C#'] | 0 |
number-of-restricted-paths-from-first-to-last-node | Modified Dijkstra's, No extra DP / BFS / DFS | modified-dijkstras-no-extra-dp-bfs-dfs-b-7xdd | \n\n# Code\ncpp []\n#define ll long long \nclass Solution {\npublic:\n int countRestrictedPaths(int n, vector<vector<int>>& edges) {\n ll M = 1e9 + 7; | amazing_ankit | NORMAL | 2024-12-07T14:48:22.979487+00:00 | 2024-12-07T14:48:22.979524+00:00 | 11 | false | \n\n# Code\n```cpp []\n#define ll long long \nclass Solution {\npublic:\n int countRestrictedPaths(int n, vector<vector<int>>& edges) {\n ll M = 1e9 + 7;\n vector<vector<pair<ll,ll>>> adjMat(n+1, vector<pair<ll,ll>>());\n for(auto edge: edges){\n adjMat[edge[0]].push_back({edge[1], edge[2]});\n adjMat[edge[1]].push_back({edge[0], edge[2]});\n }\n\n vector<ll> minDist(n+1, -1);\n vector<ll> path(n+1, 0);\n\n set<pair<ll,ll>> pq;\n\n minDist[n] = 0;\n path[n] = 1;\n pq.insert({minDist[n], n});\n\n while(!pq.empty()){\n ll curNode = (*pq.begin()).second;\n ll curDist = (*pq.begin()).first;\n pq.erase(pq.begin());\n for(pair<ll,ll> adjNode : adjMat[curNode]){\n ll newDist = curDist + adjNode.second;\n if(minDist[adjNode.first] == -1 || minDist[adjNode.first] >= newDist){\n pq.erase({minDist[adjNode.first], adjNode.first});\n minDist[adjNode.first] = newDist;\n pq.insert({minDist[adjNode.first], adjNode.first});\n }\n if(minDist[adjNode.first] > curDist){\n path[adjNode.first] += path[curNode];\n path[adjNode.first]%= M;\n }\n }\n }\n return path[1];\n }\n};\n``` | 0 | 0 | ['C++'] | 0 |
number-of-restricted-paths-from-first-to-last-node | Dijkstra | DP | Memoized DFS | Optimal | C++ | dijkstra-dp-memoized-dfs-optimal-c-by-ad-eny2 | Time Complexity: O((E + V) log V)\nSpace Complexity: O(E + V)\n\ntypedef pair<int, int> pii;\nconst int MOD = 1e9 + 7;\nclass Solution {\n vector<int> dijkst | adityabhongade | NORMAL | 2024-11-28T16:57:41.557308+00:00 | 2024-11-28T16:57:41.557349+00:00 | 1 | false | **Time Complexity**: O((E + V) log V)\n**Space Complexity**: O(E + V)\n```\ntypedef pair<int, int> pii;\nconst int MOD = 1e9 + 7;\nclass Solution {\n vector<int> dijkstra(const vector<vector<pii>>& adj, int src) {\n vector<int> dist(src + 1, INT_MAX);\n \xA0 \xA0 \xA0 \xA0dist[src] = 0;\n priority_queue<pii, vector<pii>, greater<pii>> minHeap;\n minHeap.push({0, src});\n while (!minHeap.empty()) {\n auto [cost, vertex] = minHeap.top();\n minHeap.pop();\n if (cost > dist[vertex]) {\n continue;\n }\n for (const auto& p : adj[vertex]) {\n auto [weight, ngbr] = p;\n if (dist[vertex] + weight < dist[ngbr]) {\n dist[ngbr] = dist[vertex] + weight;\n minHeap.push({dist[ngbr], ngbr});\n }\n }\n }\n return dist;\n }\n int dfs(const vector<vector<pii>>& adj, const vector<int>& v, vector<int>& dp, int node) {\n if (node == 1) {\n return 1;\n }\n if (dp[node] != -1) {\n return dp[node];\n }\n int a = 0;\n for (const auto& p : adj[node]) {\n int ngbr = p.second;\n if (v[node] < v[ngbr]) {\n a = (a + dfs(adj, v, dp, ngbr)) % MOD;\n }\n }\n return dp[node] = a;\n }\npublic:\n int countRestrictedPaths(int n, vector<vector<int>>& edges) {\n vector<vector<pii>> adj(n + 1);\n for (const auto& v : edges) {\n adj[v[0]].push_back({v[2], v[1]});\n adj[v[1]].push_back({v[2], v[0]});\n }\n auto v = dijkstra(adj, n);\n vector<int> dp(n + 1, -1);\n return dfs(adj, v, dp, n);\n }\n};\n``` | 0 | 0 | [] | 0 |
number-of-restricted-paths-from-first-to-last-node | Dijkstra + DFS + DP | dijkstra-dfs-dp-by-up41guy-ifbs | javascript []\nclass MinMaxPriorityQueue {\n\n #heap = []\n #compare;\n\n constructor(compare) {\n this.#heap = [];\n this.#compare = compare || ((a, b | Cx1z0 | NORMAL | 2024-11-26T09:16:54.064760+00:00 | 2024-11-26T09:16:54.064797+00:00 | 4 | false | ```javascript []\nclass MinMaxPriorityQueue {\n\n #heap = []\n #compare;\n\n constructor(compare) {\n this.#heap = [];\n this.#compare = compare || ((a, b) => a - b) //By default, keep it MinHeap\n }\n\n // Add a new element to the priority queue\n enqueue = (value) => {\n this.#heap.push(value);\n this.#heapifyUp(this.#heap.length - 1);\n }\n\n // Remove and return the element with the highest priority (smallest for min-heap, largest for max-heap)\n dequeue = () => {\n if (this.#heap.length === 0) return null;\n const root = this.#heap[0];\n const end = this.#heap.pop();\n if (this.#heap.length > 0) {\n this.#heap[0] = end;\n this.#heapifyDown(0);\n }\n return root;\n }\n\n // Peek at the element with the highest priority without removing it\n peek = () => {\n return this.#heap.length > 0 ? this.#heap[0] : null;\n }\n\n // Check if the priority queue is empty\n isEmpty = () => {\n return this.#heap.length === 0;\n }\n\n // Get the size of the priority queue\n size = () => {\n return this.#heap.length;\n }\n\n // Maintain heap property by moving element up\n #heapifyUp = (index) => {\n let parent = Math.floor((index - 1) / 2);\n while (index > 0 && this.#compare(this.#heap[index], this.#heap[parent]) < 0) {\n this.#swap(index, parent)\n index = parent;\n parent = Math.floor((index - 1) / 2);\n }\n }\n\n // Maintain heap property by moving element down\n #heapifyDown = (index) => {\n const length = this.#heap.length;\n let left = 2 * index + 1;\n let right = 2 * index + 2;\n let extreme = index;\n\n if (left < length && this.#compare(this.#heap[left], this.#heap[extreme]) < 0) {\n extreme = left;\n }\n\n if (right < length && this.#compare(this.#heap[right], this.#heap[extreme]) < 0) {\n extreme = right;\n }\n\n if (extreme !== index) {\n this.#swap(index, extreme)\n this.#heapifyDown(extreme);\n }\n }\n\n #swap = (i, j) => {\n [this.#heap[i], this.#heap[j]] = [this.#heap[j], this.#heap[i]]\n }\n}\n\n/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number}\n */\nconst countRestrictedPaths = function (n, edges) {\n const MOD = 1e9 + 7;\n\n // Build adjacency list\n const graph = Array.from({ length: n + 1 }, () => []);\n for (const [u, v, weight] of edges) {\n graph[u].push([v, weight]);\n graph[v].push([u, weight]);\n }\n\n // Step 1: Dijkstra\'s Algorithm to compute shortest distances from node `n`\n const dist = Array(n + 1).fill(Infinity);\n dist[n] = 0;\n\n // Using MinMaxPriorityQueue for Dijkstra\n const pq = new MinMaxPriorityQueue((a, b) => a[0] - b[0]); // MinHeap based on distance\n pq.enqueue([0, n]); // [distance, node]\n\n while (!pq.isEmpty()) {\n const [d, u] = pq.dequeue();\n if (d > dist[u]) continue;\n\n for (const [v, weight] of graph[u]) {\n if (dist[u] + weight < dist[v]) {\n dist[v] = dist[u] + weight;\n pq.enqueue([dist[v], v]);\n }\n }\n }\n\n // Step 2: DFS with memoization to count restricted paths\n const memo = Array(n + 1).fill(-1);\n\n const dfs = (node) => {\n if (node === n) return 1;\n if (memo[node] !== -1) return memo[node];\n\n let paths = 0;\n for (const [neighbor] of graph[node]) {\n if (dist[node] > dist[neighbor]) {\n paths = (paths + dfs(neighbor)) % MOD;\n }\n }\n\n return memo[node] = paths\n };\n\n return dfs(1);\n};\n``` | 0 | 0 | ['Dynamic Programming', 'Graph', 'Topological Sort', 'Heap (Priority Queue)', 'Shortest Path', 'JavaScript'] | 0 |
check-if-the-sentence-is-pangram | Simple solution, no set/map | simple-solution-no-setmap-by-korney_a-xmog | ```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n int seen = 0;\n for(char c : sentence.toCharArray()) {\n | korney_a | NORMAL | 2021-04-18T04:12:35.290570+00:00 | 2021-04-18T04:12:35.290598+00:00 | 16,396 | false | ```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n int seen = 0;\n for(char c : sentence.toCharArray()) {\n int ci = c - \'a\';\n seen = seen | (1 << ci);\n }\n return seen == ((1 << 26) - 1);\n }\n} | 264 | 7 | [] | 33 |
check-if-the-sentence-is-pangram | [Java/C++/Python] Set Solution | javacpython-set-solution-by-lee215-0gwg | \n# Explanation\nPut all characters in a set,\nreturn if the size of set equals to 26.\nCan return earlier if you like.\n\n\n# Complexity\nTime O(n)\nSpace O(26 | lee215 | NORMAL | 2021-04-18T04:02:35.829059+00:00 | 2021-04-18T04:54:31.846558+00:00 | 15,493 | false | \n# **Explanation**\nPut all characters in a set,\nreturn if the size of set equals to 26.\nCan return earlier if you like.\n<br>\n\n# **Complexity**\nTime `O(n)`\nSpace `O(26)`\n<br>\n\n**Java**\n```java\n public boolean checkIfPangram(String sentence) {\n Set<Character> s = new HashSet<>();\n for (int i = 0; i < sentence.length(); ++i)\n s.add(sentence.charAt(i));\n return s.size() == 26;\n }\n```\n\n**C++**\n```cpp\n bool checkIfPangram(string sentence) {\n set<int> s;\n for (auto& c: sentence)\n s.insert(c);\n return s.size() == 26;\n }\n```\n**C++, 1-line**\nby @alvin-777\n```cpp\n bool checkIfPangram(string s) {\n return set<char>(s.begin(), s.end()).size() == 26;\n }\n```\n**Python**\n```py\n def checkIfPangram(self, s):\n return len(set(s)) == 26\n```\n | 150 | 4 | [] | 29 |
check-if-the-sentence-is-pangram | Java Simple and easy to understand solution, 1 ms, faster than 100.00%, clean code with comments | java-simple-and-easy-to-understand-solut-u5sb | PLEASE UPVOTE IF YOU LIKE THIS SOLUTION\n\n\n\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n boolean[] letters = new boolean[ | satyaDcoder | NORMAL | 2021-04-18T04:43:17.698684+00:00 | 2021-04-18T04:43:17.698720+00:00 | 7,344 | false | **PLEASE UPVOTE IF YOU LIKE THIS SOLUTION**\n\n\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n boolean[] letters = new boolean[26];\n \n for(char c : sentence.toCharArray()) {\n letters[c - \'a\'] = true;\n }\n \n //find any letter that not exist\n for(boolean existLetter : letters) {\n if(!existLetter) return false;\n }\n \n return true;\n }\n}\n``` | 75 | 3 | ['Java'] | 5 |
check-if-the-sentence-is-pangram | Simple java 0ms | simple-java-0ms-by-guptayash3-v3x6 | \nclass Solution {\n public boolean checkIfPangram(String sentence) {\n\t\tif (sentence.length() < 26) {\n\t\t\treturn false;\n\t\t}\n\t\tString alphas = "ab | guptayash3 | NORMAL | 2021-05-10T18:44:48.487855+00:00 | 2021-05-10T18:44:48.487898+00:00 | 4,351 | false | ```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n\t\tif (sentence.length() < 26) {\n\t\t\treturn false;\n\t\t}\n\t\tString alphas = "abcdefghijklmnopqrstuvwxyz";\n\t\tfor (int i = 0; i < alphas.length(); i++) {\n\t\t\tif (sentence.indexOf(alphas.charAt(i)) == -1) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n``` | 54 | 2 | ['Java'] | 5 |
check-if-the-sentence-is-pangram | C++ || 0ms || Short & Simple Code || ✅⭐⭐ | c-0ms-short-simple-code-by-palashhh-tt65 | DO UPVOTE IF IT HELPS !!!!\n\n--------------------------------------------------------\n\nIntuition 1 - Using a frequency vector store to store count and then t | palashhh | NORMAL | 2022-10-17T03:43:00.458892+00:00 | 2022-10-17T06:42:16.673155+00:00 | 5,286 | false | ***DO UPVOTE IF IT HELPS !!!!***\n\n--------------------------------------------------------\n\n**Intuition 1 -** Using a frequency vector store to store count and then traversing it to check for any 0 occurence.\n\n\tbool checkIfPangram(string sentence) {\n \n vector<int> freq(26); //create a frequency vector \n \n for(auto ch:sentence) freq[ch-\'a\']++; //update count of each character\n \n for(auto it:freq){ //traverse freq vector\n if(it==0) return false; //if any aplhabet\'s occurence is 0\n } //return false;\n return true;\n }\n\t\n---------------------------------------------------\n\n**Intuition 2 -** Using a hash set, push all characters of the given string into hash set and check if set\'s size == 26\n\t\n\tbool checkIfPangram(string sentence) {\n \n unordered_set<char> st (sentence.begin(), sentence.end()); //push all characters of string into set\n return st.size()==26; //check if it\'s size = 26 or not\n\t\n\t}\n\t\n | 49 | 0 | ['C'] | 5 |
check-if-the-sentence-is-pangram | [ALL Languages] ONLY 1 Line ! | all-languages-only-1-line-by-ethanrao-24nc | \n# Code\ncpp []\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n return unordered_set<char>(sentence.begin(), sentence.end()).si | ethanrao | NORMAL | 2022-10-17T00:45:50.966237+00:00 | 2022-10-17T00:51:03.368397+00:00 | 6,317 | false | \n# Code\n```cpp []\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n return unordered_set<char>(sentence.begin(), sentence.end()).size() == 26;\n }\n};\n```\n\n```java []\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n return sentence.chars().distinct().count() == 26;\n }\n}\n\n\n// Stream\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n return sentence.chars().boxed().collect(Collectors.toSet()).size() == 26;\n }\n}\n\n```\n```kotlin []\nclass Solution {\n fun checkIfPangram(sentence: String): Boolean {\n return sentence.toSet().count() == 26\n }\n}\n```\n\n\n```python []\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n return len(set(sentence)) == 26\n```\n\n```javascript []\nvar checkIfPangram = function (sentence) {\n return new Set(sentence).size === 26\n};\n```\n```typescript []\nfunction checkIfPangram(sentence: string): boolean {\n return [...new Set(sentence)].length >= 26;\n};\n```\n\n | 42 | 0 | ['Python', 'C++', 'Python3', 'Kotlin', 'JavaScript'] | 3 |
check-if-the-sentence-is-pangram | C++ || 7 different approaches || clean code | c-7-different-approaches-clean-code-by-h-4mun | \nTitle: C++ || 7 different approaches || clean code\nProblem: 1832\nURL: https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2713135/c-7-dif | heder | NORMAL | 2022-10-17T07:28:32.896112+00:00 | 2022-10-17T19:04:54.110687+00:00 | 2,630 | false | <!--\nTitle: C++ || 7 different approaches || clean code\nProblem: 1832\nURL: https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2713135/c-7-different-approaches-clean-code\n-->\n\nI had way too much fun coming up with different approach to solve this problem. Please let me know if you have any suggestions for another approach or on how to improve one of the approach below. ... and leave a like before you go. :)\n\n\n### Approach 1: hash set\n\n```cpp\n static bool checkIfPangram(const string& s) {\n const unordered_set<char> seen(begin(s), end(s));\n return size(seen) == 26;\n }\n```\n\nThis can be writen as a one-liner as well:\n\n```cpp\n static bool checkIfPangram(const string& s) {\n return size(unordered_set<char>{begin(s), end(s)}) == 26;\n }\n```\n\nWe could also use a ```set```, but since we only care about the since and not the order of elements, this would just make things less efficient.\n\n**Complexity Analysis**\n * Time complexity: $$O(n)$$ we need to insert all the characters into a hash set, with each insert operation being $$O(1)$$\n * Space complexity: $$O(1)$$ as the size of the hash set is limited to 26 entries.\n\n### Approach 2: std::sort and std::unique\n\n```cpp\n static bool checkIfPangram(string& s) {\n sort(begin(s), end(s));\n return distance(begin(s), unique(begin(s), end(s))) == 26;\n }\n```\n\nInstead of modifying the string with ```unique``` again. We could also just count the number of unique elements by comparying adjacent elements, something like the following (kudos to @vonser):\n\n```cpp\n static bool checkIfPangram(string& s) {\n sort(begin(s), end(s));\n int count = 1;\n for (int i = 1; i < size(s); ++i)\n if (s[i - 1] != s[i]) ++count;\n return count == 26;\n }\n```\n\n**Complexity Analysis**\n * Time complexity: $$O(n \\log n)$$ for sorting the rest is linear or constant time\n * Space complexity: $$O(1)$$\n\n\n### Approach 3: brute force with std::string::find\n\n```cpp\n static bool checkIfPangram(const string& s) {\n for (char ch = \'a\'; ch <= \'z\'; ++ch)\n if (s.find(ch) == string::npos) return false;\n\n return true;\n }\n```\n\n**Complexity Analysis**\n * Time complexity: $$O(26 n)$$ which is $$O(n)$$\n * Space complexity: $$O(1)$$\n\n\n### Approach 4: bit masking and std::accumulate\n\n```cpp\n static bool checkIfPangram(const string& s) {\n int seen = 0;\n for (char ch : s) seen |= 1 << (ch - \'a\');\n return seen == (1 << 26) - 1;\n }\n```\n\nWe could add an early exit if we have already seen all different characters:\n\n```cpp\n static bool checkIfPangram(const string& s) {\n int seen = 0;\n int rem = 26;\n for (char ch : sentence) {\n int mask = 1 << (ch - \'a\');\n if (!(seen & mask)) {\n if (!--rem) return true;\n seen |= mask;\n }\n }\n return false;\n }\n```\n\nOr combining the two ideas above:\n\n```cpp\n static bool checkIfPangram(const string& s) {\n int seen = 0;\n for (char ch : s) {\n seen |= 1 << (ch - \'a\');\n if (seen == (1 << 26) - 1) return true;\n }\n return false;\n }\n```\n\nWithout raw loops and using ```std::accumulate``` we can turn this into a one-liner (a long though):\n\n```cpp\n static bool checkIfPangram(const string& s) {\n return accumulate(begin(s), end(s), 0, [](int seen, char ch) { return seen | (1 << (ch - \'a\')); }) == (1 << 26) - 1;\n }\n```\n\n**Complexity Analysis**\n * Time complexity: $$O(n)$$\n * Space complexity: $$O(1)$$\n\n### Approach 5: std::transform and std::reduce w/ std::bit_or\n\nThis builds on the idea from approach 4. We first transform this into bit masks first and then reduce them. What\'s intersting about ```std::reduce``` is that it coudl be executed in parallel. The down side of this approach is that we need a more extra memory. It should be noted that the reduce step doesn\'t guartee an execution order and this is only correct because ```bit_or``` (```|```) is associative and commutative.\n\n```cpp\n static bool checkIfPangram(const string& s) {\n vector<int> tmp(size(s));\n transform(begin(s), end(s), back_inserter(tmp), [](char ch) { return 1 << (ch - \'a\'); });\n return reduce(begin(tmp), end(tmp), 0, bit_or{}) == (1 << 26) - 1;\n }\n```\n\n**Complexity Analsysis**\n * Time complexity: $$O(n)$$\n * Space complexity: $$O(n)$$ for the temporary arrary\n\n### Approach 6: std::transform_reduce\n\nThe idea is the same as for approach 5, but we can reduce this to a one-liner w/o temporary memory. As w/ approach 5 this could also be executed in parallel for very large inputs.\n\n```cpp\n static bool checkIfPangram(const string& s) {\n return transform_reduce(begin(s), end(s), 0, bit_or{}, [](char ch) { return 1 << (ch - \'a\'); }) == (1 << 26) - 1;\n }\n```\n\n**Complexity Analsysis**\n * Time complexity: $$O(n)$$\n * Space complexity: $$O(1)$$\n\n### Approach 7: array\n\nLast but not least there are several variations of using an array to keep track of the characters we have seen.\n\n```cpp\n static bool checkIfPangram(const string& s) {\n array<bool, 26> seen = {};\n for (char ch : s) seen[ch - \'a\'] = true;\n // TODO(heder): std::identity is C++ 20. Is there another library function?\n return all_of(begin(seen), end(seen), [](int x) { return x; });\n }\n ```\n \n A variation of the above could be the use ```reduce``` / ```accumulate``` instead of ```all_of```. NB. we are using an ```array<char, 26>``` instead of a bool array:\n \n ```cpp\n static bool checkIfPangram(const string& s) {\n array<char, 26> seen = {};\n for (char ch : s) seen[ch - \'a\'] = 1;\n return reduce(begin(seen), end(seen)) == 26;\n }\n```\n\nSimilar to the approach with the bit mask, we could also do an early exit here:\n\n```cpp\n static bool checkIfPangram(const string& s) {\n array<bool, 128> seen = {};\n int rem = 26;\n for (char ch : s) {\n if (!seen[ch]) {\n if (!--rem) return true;\n seen[ch] = true;\n }\n }\n return false;\n }\n ```\n\n**Complexity Analsysis**\n * Time complexity: $$O(n)$$\n * Space complexity: $$O(1)$$\n\n### Appendix\n\nI have seen a few solution how are doing something like ```if (size(sentence) < 26) return false;``` which is a nice optimisation.\n\n_As always: Feedback, questions, and comments are welcome. Leaving an upvote sparks joy! :)_\n\n**p.s. Join us on the [LeetCode The Hard Way Discord Server](https://discord.gg/hFUyVyWy2E)!**\n | 39 | 0 | ['C', 'C++'] | 1 |
check-if-the-sentence-is-pangram | C++ SIMPLE QUESTION NEEDS SIMPLE SOLUTION -> O(N*26)=O(N) | c-simple-question-needs-simple-solution-ah6mg | PLZ UPVOTE IF YOU LIKED IT\n\n```\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n vector n(26,0);\n \n for(char c: | sm3210 | NORMAL | 2021-04-21T19:58:59.354806+00:00 | 2021-04-21T19:58:59.354850+00:00 | 3,367 | false | **PLZ UPVOTE IF YOU LIKED IT**\n\n```\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n vector<int> n(26,0);\n \n for(char c:sentence)n[c-\'a\']++;\n \n for(int i=0;i<26;i++)\n if(n[i]==0)return false;\n \n return true;\n }\n}; | 31 | 3 | ['C', 'C++'] | 4 |
check-if-the-sentence-is-pangram | simplest solution you have never seen if you are a beginner[beats 100% of solution check it out | simplest-solution-you-have-never-seen-if-nbd2 | IntuitionApproachComplexity
Time complexity:o(n)
Space complexity:O(1)
Code | palleabhinay | NORMAL | 2025-01-09T17:58:59.343081+00:00 | 2025-01-09T17:58:59.343081+00:00 | 1,878 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:o(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```java []
class Solution {
public boolean checkIfPangram(String sentence) {
if(sentence.length()<26) return false;
for(char ch='a';ch<='z';ch++){
if(sentence.indexOf(ch)<0){
return false;
}
}
return true;
}
}
```

| 26 | 0 | ['Hash Table', 'String', 'Java'] | 4 |
check-if-the-sentence-is-pangram | Multiple solution in python | multiple-solution-in-python-by-shubham_1-1dyt | Fastest Solution:\n\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n lst=[0]*26\n for i in sentence:\n lst[ord( | shubham_1307 | NORMAL | 2022-10-17T02:30:32.274715+00:00 | 2022-10-17T02:34:23.598353+00:00 | 2,647 | false | **Fastest Solution:**\n```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n lst=[0]*26\n for i in sentence:\n lst[ord(i)-ord(\'a\')]+=1\n return 0 not in lst\n```\n\n**One line solution:**\n```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n return len(set(sentence))==26\n``` | 25 | 0 | ['Array', 'Python', 'Python3'] | 2 |
check-if-the-sentence-is-pangram | Simple | Easy | O(1) java Solution | simple-easy-o1-java-solution-by-akhilsha-h1nm | if you like this \nplease upvote and like this\n\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n if(sentence.length()<26) retu | AkhilSharma24 | NORMAL | 2021-07-22T16:07:58.525237+00:00 | 2021-07-22T16:07:58.525284+00:00 | 2,072 | false | if you like this \n***please upvote and like this***\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n if(sentence.length()<26) return false;\n for(int i=1;i<=26;i++)\n if(sentence.indexOf((char)i+96)<0)\n return false; \n return true;\n }\n}\n``` | 24 | 3 | ['Java'] | 5 |
check-if-the-sentence-is-pangram | one liner | one-liner-by-droj-w6xw | \nclass Solution:\n def checkIfPangram(self, se: str) -> bool:\n return(len(set(se))==26) \n | droj | NORMAL | 2022-10-17T04:19:51.731357+00:00 | 2022-10-17T04:19:51.731387+00:00 | 1,314 | false | ```\nclass Solution:\n def checkIfPangram(self, se: str) -> bool:\n return(len(set(se))==26) \n``` | 22 | 1 | ['Ordered Set', 'Python'] | 4 |
check-if-the-sentence-is-pangram | [Python] One-liner | Easy Understandable Sol | Sets | python-one-liner-easy-understandable-sol-hjck | \nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n return len(set(sentence)) == 26\n\n | ayushi7rawat | NORMAL | 2021-04-18T04:10:52.014577+00:00 | 2021-04-18T04:10:52.014619+00:00 | 1,692 | false | ```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n return len(set(sentence)) == 26\n```\n | 22 | 1 | ['Python'] | 6 |
check-if-the-sentence-is-pangram | Easy 3 approaches with explanation | C++ | 100% time | One liner | easy-3-approaches-with-explanation-c-100-h955 | Very Easy solutions with quick explanation \nApproach 1 Basic approach of counting frequency\nI have used array for this approach\n100% time for this approach\n | kaustubhvats28 | NORMAL | 2021-08-03T13:28:58.603606+00:00 | 2021-12-27T11:14:09.160585+00:00 | 2,010 | false | Very Easy solutions with quick explanation \n**Approach 1 Basic approach of counting frequency**\nI have used array for this approach\n100% time for this approach\n```\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n vector<int> v(26,0);\n for(auto x:sentence)\n {\n v[x-\'a\'] = 1;\n }\n return accumulate(begin(v),end(v),0) == 26;\n }\n};\n```\n**Approach**\nCounting all the unique charcters and check if they are equal to 26 (26 letters are there in the english alphabet series)\n\n**Working of code**\n**Step 1 :**\nCreate an int array of size 26 and fill with all 0s\n```\nv = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] length = 26\n```\n**Step 2:**\nIterate all the elements of given sentence and mark the character present in our array...\n\n```\nExample if we are at character \'g\'\nso ascii value of g = 103\nso we subtract ascii value of \'a\' (97) to get the correct index of g in our array\nso now it would be 6 (103-97 = 6)\nNow you can verify that 6 is the position of \'g\' in alphabetic sequence (0 based indexing)\n\n0 1 2 3 4 5 \'6\'\na b c d e f \'g\'\n\nso we put 1 at the position 6 in our array\nv = [ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] length = 26\n\n```\nNow we will fill all the position if the corresponding character is present in the string\n\n**Step 3:**\nNow we can sum up all the elements present in the array. so if any 0 left unchanged then the sum would not be equal to 26..\nAnd that\'s the strategy...\n<hr>\n\n**Approach 2 with integer variable as container**\n100% time for this approach\n```\nbool checkIfPangram(string sentence) {\n int n = 0;\n for(auto &x:sentence){\n n|=(1<<(x-\'a\'));\n }\n cout<<n;\n return n==67108863;\n}\n```\n**Approach**\nApproach is same but as we know integer variable can hold a number of 32 bits, so istead of using a vector of size 26, we can simply use the bits of integer as flag bits (If ith bit is set then ith char in alphabetic series is presnt in the string.\n**Working of code**\n**Step 1 :**\nCreate an int var and initialise with 0\n```\nHere our variable will start behaving like vector of bool of size 32\nbits of int will be\ni = bits(00000000000000000000000000000000)\n```\n**Step 2 :**\nNow we can run a for loop same as in approach 1 to iterte over the string\nAnd we will set the ith bit of the int variable\n```\nExample : if curr char is \'d\'\nthen position of \'d\' is 4 in alphabet series...\nSo we will try to set the 4th bit if it is 0 initially by using this\nn|=(1<<(x-\'a\'));\n\nHere in 1 all bits are zeroes and last bit is 1\nSo we move that last set bit to 4th position (for \'d\') (Here x-\'a\' will give the exact position of the bit)\nAfter this we will do bit wise OR with our number so that its ith bit will became 1\n```\n**Step 3 :**\nNow we can simply compare our number with 67108863...\nHere 67108863 is the number in which last 26 bits are 1\nSo if we reach the state where all 26 bits are 1 then we can conclude that we have iterated all the characters in the alphabet as we have done in previous approach\n\n<hr>\n\n**Approach 3 with set**\nThis is not the time optimised solution, still good if you are a lazy person when it comes to typing\n```\nbool checkIfPangram(string sentence) {\n return unordered_set<char> (begin(sentence),end(sentence)).size()==26;\n}\n```\n\n**Approach**\nApproach is same but working is slightly different\n\n**Working**\n**Step 1:**\nCreate a set and fill it with all the characters present in the string..\n\n**Step 2:**\nAs per the property of sets you can not have duplicates in the set. \nSo you can simply check the size of set whether it has 26 unique elements or not\n\nTime Complexity is O(n) for all the approaches\n\n**NOTE :** If you find any errors or any improvements required, then feel free to comment down below.\n\nThanks\nGood Luck | 21 | 0 | ['Array', 'Hash Table', 'C', 'Ordered Set', 'C++'] | 4 |
check-if-the-sentence-is-pangram | JAVA || EASY SOLUTION | java-easy-solution-by-ashutosh_pandey-piyz | IF YOU LIKE THE SOLUTION\nMAKE SURE TO UPVOTE IT !\n\n\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n // Created count array t | ashutosh_pandey | NORMAL | 2022-10-17T02:45:49.104498+00:00 | 2022-10-17T02:45:49.104536+00:00 | 2,590 | false | IF YOU LIKE THE SOLUTION\nMAKE SURE TO UPVOTE IT !\n\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n // Created count array to take count of every character.\n int[] count = new int[26];\n \n // Fill our count array\n for(int i = 0; i<sentence.length(); i++)\n count[sentence.charAt(i) - \'a\']++;\n \n // Check in count array that every element is present or not !\n for(int i : count)\n if(i < 1) return false;\n \n return true;\n }\n}\n``` | 20 | 0 | ['Java'] | 4 |
check-if-the-sentence-is-pangram | Simple Solution Without Using Extra Space | simple-solution-without-using-extra-spac-huv4 | UPvote If you got it\n\n\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n \n if(sentence.length()<26 || sentence == null) | hp902 | NORMAL | 2021-06-22T15:23:44.954362+00:00 | 2021-06-22T15:23:44.954414+00:00 | 976 | false | **UPvote If you got it**\n\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n \n if(sentence.length()<26 || sentence == null)\n return false;\n \n for(char i=97;i<=122;i++){\n if(!sentence.contains(String.valueOf(i)))\n return false;\n }\n return true;\n}\n}\n``` | 20 | 3 | ['Java'] | 1 |
check-if-the-sentence-is-pangram | Javascript one-liner 100% O(n) | javascript-one-liner-100-on-by-pixel_pro-poe5 | \nvar checkIfPangram = function(sentence) {\n return new Set(sentence.split("")).size == 26;\n};\n | pixel_pro_max | NORMAL | 2021-04-18T08:12:10.872654+00:00 | 2021-04-18T08:12:10.872684+00:00 | 1,741 | false | ```\nvar checkIfPangram = function(sentence) {\n return new Set(sentence.split("")).size == 26;\n};\n``` | 18 | 1 | ['JavaScript'] | 4 |
check-if-the-sentence-is-pangram | only 1 line code for python3 | only-1-line-code-for-python3-by-hakkiot-ucw1 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | hakkiot | NORMAL | 2023-06-12T10:43:17.118343+00:00 | 2023-06-12T10:43:17.118391+00:00 | 1,104 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def checkIfPangram(self, s: str) -> bool:\n return len(set(s))==26 \n``` | 17 | 0 | ['String', 'Python3'] | 1 |
check-if-the-sentence-is-pangram | javascript one-liner | javascript-one-liner-by-ramakrishna0505-e2bx | var checkIfPangram = function(sentence) {\n return new Set([...sentence]).size === 26;\n}; | ramakrishna0505 | NORMAL | 2021-04-18T11:47:48.325772+00:00 | 2021-04-18T11:47:48.325828+00:00 | 747 | false | var checkIfPangram = function(sentence) {\n return new Set([...sentence]).size === 26;\n}; | 15 | 0 | [] | 3 |
check-if-the-sentence-is-pangram | C++/Java Count Array | cjava-count-array-by-votrubac-cv54 | C++\ncpp\nbool checkIfPangram(string sentence) {\n int cnt[26] = {}, total = 0;\n for (auto ch: sentence)\n if (++cnt[ch - \'a\'] == 1)\n | votrubac | NORMAL | 2021-04-18T04:03:52.867684+00:00 | 2021-04-18T04:03:52.867711+00:00 | 1,724 | false | **C++**\n```cpp\nbool checkIfPangram(string sentence) {\n int cnt[26] = {}, total = 0;\n for (auto ch: sentence)\n if (++cnt[ch - \'a\'] == 1)\n total++;\n return total == 26;\n}\n```\n**Java**\n```java\npublic boolean checkIfPangram(String sentence) {\n int cnt[] = new int[26], total = 0;\n for (var ch: sentence.toCharArray())\n if (++cnt[ch - \'a\'] == 1)\n total++;\n return total == 26;\n}\n``` | 15 | 1 | [] | 4 |
check-if-the-sentence-is-pangram | Java || using Frequency array || using Set || using HashMap | java-using-frequency-array-using-set-usi-xslg | 1. using Frequency Array\n\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n int [] freq=new int[26];\n for(int i=0;i<sent | kadamyogesh7218 | NORMAL | 2022-10-17T05:01:47.438947+00:00 | 2022-10-17T05:01:47.439002+00:00 | 1,273 | false | **1. using Frequency Array**\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n int [] freq=new int[26];\n for(int i=0;i<sentence.length();i++){\n freq[sentence.charAt(i)-\'a\']++;\n }\n for(int i=0;i<26;i++){\n if(freq[i]==0){\n return false;\n }\n }\n return true;\n }\n}\n\n```\n\n**2. using HashSet**\n\n```\nclass Solution{\n public boolean checkIfPangram(String sentence){\n Set<Character> set=new HashSet<>();\n for(int i=0;i<sentence.length();i++){\n set.add(sentence.charAt(i));\n }\n if(set.size()==26){\n return true;\n }\n return false;\n }\n}\n```\n\n**3. using HashMap**\n\n```\nclass Solution{\n public boolean checkIfPangram(String sentence){\n HashMap<Character,Integer> hm=new HashMap<>();\n for(int i=0;i<sentence.length();i++){\n hm.put(sentence.charAt(i),0);\n }\n if(hm.size()==26){\n return true;\n }\n return false;\n }\n}\n``` | 14 | 0 | ['Ordered Set', 'Java'] | 0 |
check-if-the-sentence-is-pangram | Python 2 different approaches | beats 96% time, O(1) solution! | python-2-different-approaches-beats-96-t-wzgl | \nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n \n # naive approach - 1\n # freq = {}\n # for i in sentenc | vanigupta20024 | NORMAL | 2021-06-16T18:44:37.017186+00:00 | 2021-06-16T18:44:37.017214+00:00 | 1,083 | false | ```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n \n # naive approach - 1\n # freq = {}\n # for i in sentence:\n # freq[i] = freq.get(i, 0) + 1\n # if len(freq) == 26: return True\n # return False\n \n # optimized approach - 2\n occurred = 0\n for i in sentence:\n temp = ord(i) - ord(\'a\')\n occurred |= (1 << temp)\n if occurred == (1 << 26) - 1:\n return True\n return False\n```\nFor more such solutions: https://github.com/vanigupta20024/Programming-Challenges | 12 | 0 | ['Python', 'Python3'] | 2 |
check-if-the-sentence-is-pangram | JAVA Solution || Beats 100% || Easy Approach | java-solution-beats-100-easy-approach-by-nzp7 | Intuition\n1. Length Check: It first checks if the sentence length is less than 26. If so, it cannot be a pangram as it wouldn\'t have enough characters to incl | saloningole | NORMAL | 2024-08-27T17:38:08.988994+00:00 | 2024-08-27T17:38:08.989023+00:00 | 1,536 | false | # Intuition\n1. Length Check: It first checks if the sentence length is less than 26. If so, it cannot be a pangram as it wouldn\'t have enough characters to include all letters.\nLetter Iteration: It then iterates through all lowercase letters from \'a\' to \'z\'.\n2. Letter Search: For each letter, it checks if it exists in the sentence using the indexOf method. If the letter is not found, it returns false as the sentence is missing that letter.\n3. Pangram Determination: If the loop completes without finding a missing letter, it means the sentence contains all letters and therefore is a pangram.\n \nThis solution is efficient as it avoids unnecessary iterations if a missing letter is found early on. The indexOf method is generally optimized for string searching, making it a suitable choice for this task.\n\n# Approach\n1. check if (the length is less than 26) then return false\n2. iterate from a to z \n3. check that the given string contains all the elements from a to z using indexOf() method in string\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n if(sentence.length()<26) return false;\n for(char ch=\'a\';ch<=\'z\';ch++){\n if(sentence.indexOf(ch)<0){\n return false;\n }\n }\n return true;\n }\n}\n``` | 11 | 0 | ['Java'] | 4 |
check-if-the-sentence-is-pangram | Easy Java Solution using HashSet Two Approaches | easy-java-solution-using-hashset-two-app-b4j6 | Approach 1\n1. Initialize HashSet:\n - Create a HashSet<Character> mp to store unique characters from the sentence.\n\n2. Add Characters to HashSet:\n - Ite | RajarshiMitra | NORMAL | 2024-05-26T09:00:13.718534+00:00 | 2024-06-21T06:20:09.315254+00:00 | 1,059 | false | # Approach 1\n1. **Initialize HashSet**:\n - Create a `HashSet<Character> mp` to store unique characters from the sentence.\n\n2. **Add Characters to HashSet**:\n - Iterate through each character in the `sentence`.\n - Add each character to the `HashSet`.\n\n3. **Check for Pangram**:\n - Iterate through all lowercase English letters from \'a\' to \'z\'.\n - For each letter, check if it is contained in the `HashSet`.\n - If any letter is not found in the `HashSet`, return `false`.\n\n4. **Return True**:\n - If all letters \'a\' to \'z\' are found in the `HashSet`, return `true`.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n HashSet<Character> mp=new HashSet<>();\n for(int i=0; i<sentence.length(); i++){\n mp.add(sentence.charAt(i));\n }\n for(char i=\'a\'; i<=\'z\'; i++){\n if(!mp.contains(i)) return false;\n }\n return true;\n }\n}\n```\n\n# Approach 2\n1. **Initialize HashSet**:\n - Create a `HashSet` named `mp` to store characters.\n\n2. **Iterate Over Sentence**:\n - Loop through each character in the input `sentence`.\n - For each character, add it to the `HashSet`.\n\n3. **Check Pangram Condition**:\n - After the loop, check the size of the `HashSet`.\n - If the size of the `HashSet` is 26 (i.e., all 26 letters of the English alphabet are present), return `true`.\n - Otherwise, return `false`.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n HashSet<Character> mp=new HashSet<>();\n for(int i=0; i<sentence.length(); i++){\n mp.add(sentence.charAt(i));\n }\n return mp.size() == 26;\n }\n}\n```\n\n\n | 11 | 0 | ['Java'] | 1 |
check-if-the-sentence-is-pangram | One liner, faster than 97% solution | one-liner-faster-than-97-solution-by-bla-c8kb | \ndef checkIfPangram(self, s: str) -> bool:\n return True if len(set(s))==26 else False\n | blackmishra | NORMAL | 2021-05-07T19:03:29.210956+00:00 | 2021-05-07T19:03:29.211000+00:00 | 888 | false | ```\ndef checkIfPangram(self, s: str) -> bool:\n return True if len(set(s))==26 else False\n``` | 11 | 1 | ['Python3'] | 4 |
check-if-the-sentence-is-pangram | Simple Python solution_O(n) | simple-python-solution_on-by-smaranjitgh-iduy | Goal: We need to check if all the letters from a-z have occured atleast once or not in a given sentence\n\n### Approach:\n\n- We don\'t care if any letter betwe | smaranjitghose | NORMAL | 2021-04-19T12:31:11.152989+00:00 | 2021-04-22T09:21:04.915262+00:00 | 1,252 | false | __Goal__: We need to check if all the letters from a-z have occured atleast once or not in a given sentence\n\n### Approach:\n\n- We don\'t care if any letter between a-z occurs more than once.\n- So we get only the single occurances of each character in the string by converting it into a set which is an ordered sequence of unique elements.\n- Now, we need to check if all the elements between a-z are there. In other words, if our resulting set has all the 26 letters of English alphabet\n- So we just check if it\'s length is 26.\n\n```python\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n\n return len(set(sentence)) == 26\n```\n\n__TIME COMPLEXITY__: O(n)\n\n- set(str) would be O(k) where k is the length of the string k . [Reference](https://stackoverflow.com/questions/34642155/what-is-time-complexity-of-a-list-to-set-conversion/34642209)\n- len() has O(1) in python. [Reference](https://stackoverflow.com/questions/1115313/cost-of-len-function)\n\n_NOTE_: In case you have anything to add or suggest any corrections, please do so in the comments. I am open to feedback! | 11 | 0 | ['String', 'Python', 'Python3'] | 4 |
check-if-the-sentence-is-pangram | easy | easy-by-bhavya32code-ze1w | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Bhavya32code | NORMAL | 2023-01-06T01:16:42.514137+00:00 | 2023-01-06T01:16:42.514208+00:00 | 750 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic: \n bool checkIfPangram(string s) {\n vector<int>v(26);\n for(int p=0;p<s.length();p++){\n v[s[p]-97]++;\n }\n for(int p=0;p<26;p++){\n if(v[p]==0){\n return false;\n }\n }\n return true;\n }\n};\n``` | 10 | 0 | ['C++'] | 0 |
check-if-the-sentence-is-pangram | Easy || 1 liner || 0 ms || 100% || Explained || Java, C++, Python, JS, Python3 | easy-1-liner-0-ms-100-explained-java-c-p-z4nd | A pangram is a sentence where every letter of the English alphabet appears at least once...\nGiven a string sentence containing only lowercase English letters, | PratikSen07 | NORMAL | 2022-10-17T05:58:56.152960+00:00 | 2022-10-17T06:05:15.805233+00:00 | 1,766 | false | A pangram is a sentence where every letter of the English alphabet appears at least once...\nGiven a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise...\n\n# **Java Solution:**\n```\n// Time Complexity: O(n)\n// Space Complexity: O(1)\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n // Create a hashSet containing only unique values...\n Set<Character> hset = new HashSet<>();\n // Add all elements to hset...\n for (final char ch : sentence.toCharArray())\n hset.add(ch);\n // Check the size of the hset if it is 26 then the string is a pangram...\n return hset.size() == 26;\n }\n}\n```\n\n# **C++ Solution:**\n```\n/** Approach 1 **/\n// Time Complexity: O(n)\n// Space Complexity: O(1)\n// Runtime: 0 ms, faster than 100.00% of C++ online submissions for Check if the Sentence Is Pangram.\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n // Add all elements to set and check if there are 26 different letters...\n return set<char>(begin(sentence), end(sentence)).size() == 26;\n }\n};\n---------------------------------------------------------------------------------------------------------------------------------------------------------------\n/** Approach 2 **/\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n // Check if length of sentence is less than 26, then return false...\n if (sentence.size() < 26) return false;\n // Declare an Array with a size of 26 & initialize each index value as 0...\n int arr[26] = {0};\n // Iterate every character of the given string and store the occurrence of the particular character...\n for(char ch : sentence) {\n // If ch equal to space, continue...\n if (ch == \' \') continue;\n // Initialize a index...\n // Suppose a character is \u2018a\u2018. then idx = (int)a-97 = 97 \u2013 97 = 0...\n int idx = (int)ch - 97;\n // arr[idx] = arr[idx] + 1 => arr[0] = arr[0] + 1 = 0 + 1 = 1...\n arr[idx]++;\n }\n for (int i : arr) {\n // Now check if any value of the arr is 0 then the string is not a Pangram...\n if (i == 0)\n return false;\n }\n // Otherwise the sentece is a Pangram...\n return true;\n }\n};\n```\n\n# **Python / Python3 Solution:**\n```\n# Time Complexity: O(n)\n# Space Complexity: O(1)\nclass Solution(object):\n def checkIfPangram(self, sentence):\n # Add all elements to set and check if there are 26 different letters...\n return len(set(sentence)) == 26\n```\n \n# **JavaScript Solution:**\n```\n// Time Complexity: O(n)\n// Space Complexity: O(1)\nvar checkIfPangram = function(sentence) {\n return new Set(sentence.split("")).size === 26\n};\n```\n**I am working hard for you guys...\nPlease upvote if you found any help with this code...** | 10 | 0 | ['C', 'Python', 'Java', 'Python3', 'JavaScript'] | 1 |
check-if-the-sentence-is-pangram | [Java] 0ms solution faster than %100 of solutions | java-0ms-solution-faster-than-100-of-sol-qve2 | \n //Runtime: 0 ms, faster than 100.00% of Java online submissions for Check if the Sentence Is Pangram.\n public boolean checkIfPangram(String sentence) | tunato | NORMAL | 2021-09-10T06:58:42.820500+00:00 | 2021-09-10T06:58:42.820551+00:00 | 844 | false | ```\n //Runtime: 0 ms, faster than 100.00% of Java online submissions for Check if the Sentence Is Pangram.\n public boolean checkIfPangram(String sentence) {\n String alphabet = "abcdefghijklmnopqrstuvwxyz"; \n for (char ch : alphabet.toCharArray()) {\n if (sentence.indexOf(ch) == -1) return false;\n } \n return true;\n }\n``` | 10 | 3 | ['Java'] | 3 |
check-if-the-sentence-is-pangram | JAVA Easy Solution 🔥100% Faster Code 🔥Beginner Friendly🔥 | java-easy-solution-100-faster-code-begin-bked | Please UPVOTE if helps.\n\n# Complexity\n- Time complexity: O(n^2)\n Add your time complexity here, e.g. O(n) \n\n# Code\n\nclass Solution {\n public boolean | diyordev | NORMAL | 2023-12-16T21:40:07.750968+00:00 | 2023-12-16T21:40:07.750983+00:00 | 1,332 | false | # Please UPVOTE if helps.\n\n# Complexity\n- Time complexity: $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n char ch=\'a\';\n for(int i=0; i < 26; i++)\n if(sentence.contains(String.valueOf(ch))) ch++;\n else return false;\n return true;\n }\n}\n``` | 9 | 0 | ['Java'] | 3 |
check-if-the-sentence-is-pangram | Python || 2 lines, sets || T/S: 94% / 99% | python-2-lines-sets-ts-94-99-by-spauldin-6oqd | \nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n\n return len(set(sentence)) == 26\n\nhttps://leetcode.com/problems/check-if-th | Spaulding_ | NORMAL | 2022-10-24T18:17:40.395736+00:00 | 2024-06-20T17:16:47.326619+00:00 | 314 | false | ```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n\n return len(set(sentence)) == 26\n```\n[https://leetcode.com/problems/check-if-the-sentence-is-pangram/submissions/599255950/](https://leetcode.com/problems/check-if-the-sentence-is-pangram/submissions/599255950/)\n\nI could be wrong, but I think that time complexity is *O*(*N*) and space complexity is *O*(*N*), in which *N* ~ `len(sentence)`. | 9 | 0 | ['Python', 'Python3'] | 1 |
check-if-the-sentence-is-pangram | Easy to understand Java solution | easy-to-understand-java-solution-by-mann-av5n | The thinking is intuitive:\n\n\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n boolean a = false;\n boolean b = false;\n | Manny6902 | NORMAL | 2022-10-17T02:43:38.405975+00:00 | 2022-10-17T02:43:38.406010+00:00 | 735 | false | The thinking is intuitive:\n\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n boolean a = false;\n boolean b = false;\n boolean c = false;\n boolean d = false;\n boolean e = false;\n boolean f = false;\n boolean g = false;\n boolean h = false;\n boolean ii = false;\n boolean j = false;\n boolean k = false;\n boolean l = false;\n boolean m = false;\n boolean n = false;\n boolean o = false;\n boolean p = false;\n boolean q = false;\n boolean r = false;\n boolean s = false;\n boolean t = false;\n boolean u = false;\n boolean v = false;\n boolean w = false;\n boolean x = false;\n boolean y = false;\n boolean z = false;\n for (int i = 0; i < sentence.length(); i++) {\n if (sentence.charAt(i) == \'a\') {\n a = true;\n } else if (sentence.charAt(i) == \'b\') {\n b = true;\n } else if (sentence.charAt(i) == \'c\') {\n c = true;\n } else if (sentence.charAt(i) == \'d\') {\n d = true;\n } else if (sentence.charAt(i) == \'e\') {\n e = true;\n } else if (sentence.charAt(i) == \'f\') {\n f = true;\n } else if (sentence.charAt(i) == \'g\') {\n g = true;\n } else if (sentence.charAt(i) == \'h\') {\n h = true;\n } else if (sentence.charAt(i) == \'i\') {\n ii = true;\n } else if (sentence.charAt(i) == \'j\') {\n j = true;\n } else if (sentence.charAt(i) == \'k\') {\n k = true;\n } else if (sentence.charAt(i) == \'l\') {\n l = true;\n } else if (sentence.charAt(i) == \'m\') {\n m = true;\n } else if (sentence.charAt(i) == \'n\') {\n n = true;\n } else if (sentence.charAt(i) == \'o\') {\n o = true;\n } else if (sentence.charAt(i) == \'p\') {\n p = true;\n } else if (sentence.charAt(i) == \'q\') {\n q = true;\n } else if (sentence.charAt(i) == \'r\') {\n r = true;\n } else if (sentence.charAt(i) == \'s\') {\n s = true;\n } else if (sentence.charAt(i) == \'t\') {\n t = true;\n } else if (sentence.charAt(i) == \'u\') {\n u = true;\n } else if (sentence.charAt(i) == \'v\') {\n v = true;\n } else if (sentence.charAt(i) == \'w\') {\n w = true;\n } else if (sentence.charAt(i) == \'x\') {\n x = true;\n } else if (sentence.charAt(i) == \'y\') {\n y = true;\n } else if (sentence.charAt(i) == \'z\') {\n z = true;\n }\n }\n return a && b && c && d && e && f && g && h && ii && j && k && l && m && n && o && p && q && r && s && t && u && v && w && x && y && z;\n }\n}\n``` | 8 | 1 | ['Java'] | 4 |
check-if-the-sentence-is-pangram | Java | Bitwise OR | 1 ms | java-bitwise-or-1-ms-by-ffbit-xjkk | This solution uses 26 bits in an integer for each of the 26 lowercase English letters. Then, it checks if all the 26 least significant bits are set.\n\nTime com | ffbit | NORMAL | 2021-04-24T19:27:12.191734+00:00 | 2021-04-24T19:27:40.598082+00:00 | 386 | false | This solution uses 26 bits in an integer for each of the 26 lowercase English letters. Then, it checks if all the 26 least significant bits are set.\n\nTime complexity: `O(N)`.\nSpace complexity: `O(N)`.\n\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n var seen = 0;\n for (var i = 0; i < sentence.length(); i++) {\n seen |= 1 << (sentence.charAt(i) - \'a\');\n }\n return seen == (1 << 26) - 1;\n }\n}\n``` | 8 | 2 | ['Java'] | 1 |
check-if-the-sentence-is-pangram | c++ || self explanatory | c-self-explanatory-by-rajat_gupta-2hf1 | \nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n vector<int> vec(26,0);\n for(char ch : sentence){\n vec[ch-\' | rajat_gupta_ | NORMAL | 2021-04-18T04:02:05.064589+00:00 | 2021-04-18T04:10:12.370553+00:00 | 511 | false | ```\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n vector<int> vec(26,0);\n for(char ch : sentence){\n vec[ch-\'a\']++;\n }\n int zero_count = count(vec.begin(), vec.end(), 0);\n return zero_count==0;\n }\n};\n``` \n\n```\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n unordered_set<char> set(sentence.begin(), sentence.end());\n return set.size() == 26;\n }\n};\n```\n**Feel free to ask any question in the comment section.**\nI hope that you\'ve found the solution useful.\nIn that case,**please do upvote and encourage me** to on my quest to document all leetcode problems\uD83D\uDE03\nHappy Coding :)\n | 8 | 3 | ['C', 'C++'] | 1 |
check-if-the-sentence-is-pangram | Optimizing space complexity using bitmasks (with Intuition) | optimizing-space-complexity-using-bitmas-09j4 | \nbool checkIfPangram(string sentence) {\n\tint mask = 0;\n\tfor(char &c : sentence) mask |= (1 << (c - \'a\'));\n\treturn (1 + mask) == (1 << 26);\n}\n\n\nSpac | dhruv10050 | NORMAL | 2022-10-18T09:13:37.107133+00:00 | 2022-10-18T15:33:59.178045+00:00 | 234 | false | ```\nbool checkIfPangram(string sentence) {\n\tint mask = 0;\n\tfor(char &c : sentence) mask |= (1 << (c - \'a\'));\n\treturn (1 + mask) == (1 << 26);\n}\n```\n\n**Space Complexity**\n*We can reduce our space complexity from* \n* **O( 26 * 4bytes (*int*) )** using set / hashset to\n* **O( 26 * 1byte (*bool*) )** using boolean array to\n* **O( 4bytes (*int*) )** using a single integer\n\n\n**Intuition**\n* A boolean array can be used to mark the characters which occur in the string.\n* The boolean values can be represented using bits of an integer.\n* Since there are only 26 characters, we can easily accomodate them inside the available 31 bits of an integer.\n\n\n**Advantage of integer over boolean array**\n* In order to check presence of characters in the boolean array, you have to use a loop of size 26.\n* For an integer, If all the characters are present, the integer will have 26 bits[0 - 25] set from its left end.\n* Adding another 1 to it will set the 26th bit and unset the bits on the right.\n*eg : 0111 + 1 = 1000*\n* Thus the condition can be checked in a single step, removing the need of a loop. (*please refer the source code*) | 7 | 0 | ['Bit Manipulation', 'C', 'Bitmask'] | 2 |
check-if-the-sentence-is-pangram | Simple c++ Soln | simple-c-soln-by-jyot_150-6jvx | \nclass Solution {\npublic: \n bool checkIfPangram(string s) {\n vector<int>v(26);\n for(int p=0;p<s.length();p++){\n v[s[p]-97]++ | jyot_150 | NORMAL | 2022-10-17T04:40:35.278412+00:00 | 2022-10-17T04:40:35.278452+00:00 | 1,705 | false | ```\nclass Solution {\npublic: \n bool checkIfPangram(string s) {\n vector<int>v(26);\n for(int p=0;p<s.length();p++){\n v[s[p]-97]++;\n }\n for(int p=0;p<26;p++){\n if(v[p]==0){\n return false;\n }\n }\n return true;\n }\n};\n``` | 7 | 0 | [] | 1 |
check-if-the-sentence-is-pangram | ✅✔ SIMPLE PYTHON3 SOLUTION ✅✔ ONE-LINE FASTEr | simple-python3-solution-one-line-faster-4qn8e | UPVOTE me if it is helpful**\n\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n return(len(set(list(sentence))) == 26)\n | rajukommula | NORMAL | 2022-09-14T03:51:30.175993+00:00 | 2022-09-14T03:51:30.176040+00:00 | 526 | false | ***UPVOTE*** me if it is helpful**\n``` \nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n return(len(set(list(sentence))) == 26)\n``` | 7 | 0 | ['Python', 'Python3'] | 1 |
check-if-the-sentence-is-pangram | Best Solution for sure :") | best-solution-for-sure-by-hardikjain-zi4h | \nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n int res = ((1 << 26) - 1),check = 0;\n for(int i = 0; i < sentence.size( | Hardikjain_ | NORMAL | 2021-09-25T18:07:57.217426+00:00 | 2021-09-25T18:07:57.217475+00:00 | 191 | false | ```\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n int res = ((1 << 26) - 1),check = 0;\n for(int i = 0; i < sentence.size(); i++)\n {\n check = check | (1 << (sentence[i] - \'a\'));\n if(check == res) return 1;\n }\n return 0;\n }\n};\n```\n | 7 | 0 | ['Bit Manipulation', 'C'] | 0 |
check-if-the-sentence-is-pangram | Python One liner faster than 99.15% | python-one-liner-faster-than-9915-by-ano-0n8b | \n\t\tdef checkIfPangram(self, sentence):\n\t\t\treturn len(set(sentence)) == 26\n\t\t\t\n\t\t\t\nEdited: The code is more optamized by @chrislwzy. Thanks buddy | anonymous_coder404 | NORMAL | 2021-04-24T07:58:10.441532+00:00 | 2021-04-24T10:52:42.408690+00:00 | 416 | false | \n\t\tdef checkIfPangram(self, sentence):\n\t\t\treturn len(set(sentence)) == 26\n\t\t\t\n\t\t\t\nEdited: The code is more optamized by @chrislwzy. Thanks buddy. | 7 | 2 | [] | 5 |
check-if-the-sentence-is-pangram | JS | Hash table | With explanation | js-hash-table-with-explanation-by-karina-5dhh | To solve this problem, we can use a Hash table (in this case, I use Set()). \nThe first thing to do is check for the number of characters in the string, if it i | Karina_Olenina | NORMAL | 2022-10-18T08:44:15.163691+00:00 | 2022-10-18T08:44:15.163731+00:00 | 545 | false | To solve this problem, we can use a Hash table (in this case, I use Set()). \n**The first** thing to do is check for the number of characters in the string, if it is less than 26, it makes no sense to check it. \nIf the string is still larger, we **create a new Set()**, filling it with characters from the string, and setting its size to 26, since Set() can only store **unique** values, 26 unique letters will fall into it, which will mean the **true** in this task, otherwise, if there are less than 26 unique letters - **false**.\n\n```\nvar checkIfPangram = function (sentence) {\n\n if (sentence.length < 26) return false;\n return new Set(sentence.split("")).size === 26;\n\n};\n```\n\nI hope I was able to explain clearly.\n**Happy coding!** \uD83D\uDE43 | 6 | 0 | ['Hash Table', 'String', 'Ordered Set', 'JavaScript'] | 1 |
check-if-the-sentence-is-pangram | Python3 O(n) || O(1) or O(26) # Runtime: 40ms 71.99% || Memory: 13.9mb 54.83% | python3-on-o1-or-o26-runtime-40ms-7199-m-0rrl | \nclass Solution:\n# O(n) || O(1) because we are dealing with lower case english alphabets O(26)\n# Runtime: 40ms 71.99% || Memory: 13.9mb 54.83%\n def c | arshergon | NORMAL | 2022-07-07T12:06:02.927668+00:00 | 2022-07-09T04:48:26.682809+00:00 | 221 | false | ```\nclass Solution:\n# O(n) || O(1) because we are dealing with lower case english alphabets O(26)\n# Runtime: 40ms 71.99% || Memory: 13.9mb 54.83%\n def checkIfPangram(self, sentence: str) -> bool:\n allAlpha = [False] * 26\n\n for char in sentence:\n index = ord(char) - ord(\'a\')\n allAlpha[index] = True\n\n\n return all(allAlpha[i] for i in range(26))\n\n``` | 6 | 0 | ['Python', 'Python3'] | 0 |
check-if-the-sentence-is-pangram | JAVA simple solution 100% faster :) | java-simple-solution-100-faster-by-anant-9jkw | Instead of iterating through sentence string, iterating through these 26 characters will be faster.\n\nclass Solution {\n public boolean checkIfPangram(Strin | AnanthaPerumal | NORMAL | 2021-11-08T16:41:36.617081+00:00 | 2021-11-08T16:41:36.617113+00:00 | 275 | false | Instead of iterating through sentence string, iterating through these 26 characters will be faster.\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n if(sentence.length() < 26) return false;\n for(char c = \'a\' ; c <= \'z\'; c++){\n if(sentence.indexOf(c) == -1){\n return false;\n }\n }\n return true;\n }\n}\n}\n``` | 6 | 1 | ['Java'] | 1 |
check-if-the-sentence-is-pangram | C++ | Bit Manipulation | c-bit-manipulation-by-wrong_answer-zm9o | Edit : Adding explanation\n\nWe need to check if a string has all the 26 lowercase english alphabets from \'a\' to \'z\'. Also, we do not care about the number | wrong_answer | NORMAL | 2021-06-21T13:07:51.416966+00:00 | 2021-06-27T02:46:30.432860+00:00 | 165 | false | Edit : Adding explanation\n\nWe need to check if a string has all the 26 lowercase english alphabets from \'a\' to \'z\'. Also, we do not care about the number of occurances, the only thing we need to check is : each character should have atleast 1 occurance. So we can use a set and keep inserting all the characters of the string till the end and finally we can check if the set size is equal to 26. But we can notice that in summary we are only required to store 26 elements at max in the set so we can use bit manipulation instead of a set to do it. \nWe can use an integer\'s 26 least significant bits to store presence of each character , i.e.\n\n\n```\nb26 b25 ... b2 b1\n```\n\nwhere `bi` is the bit at `ith` position. We will set `ith` bit if we have `ith` english lowercase alphabet in the string (starting from \'a\' ). We will iterate over the string, store the presence of each lowercase english alphabet like below : \n\ne.g. If we get \'a\' , we will set the 1st bit using , \n```\nn = n | (1<<(c-\'a\'))\n```\nThis will set the 1st bit ( read [this](https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit) if you are unable to understand the above statement ) , similarly if we get \'z\', we will set the 26th bit and at last, after we are done iterating over the complete string, we just need to check if all the 26bits of the number are set (i.e. all the 26 lowercase english alphabtes are present in the input string). We can do this by 1 simple observation, \n```\n1111 (base 2) = 15 (base 10)\n111111 (base 2) = 63 (base 10)\n```\n\nIn general, if the `n` bit binary number contains only `n` set bits, then its decimal equivalent = `2^(number of bits) - 1` \n\nSo, we can check if all bits are set using above observation and return true only if \n\n```\nn == pow(2,26) -1\n```\n\nC++ CODE : \n\n``` \nbool checkIfPangram(string s) {\n int n = 0;\n for(char c:s){\n n = n | (1<<(c-\'a\')); // set character\'s corresponding bit\n }\n return n==pow(2,26)-1; // check if all 26 bits are set\n } | 6 | 0 | ['Bit Manipulation'] | 1 |
check-if-the-sentence-is-pangram | Python3: one-line solution | python3-one-line-solution-by-lopkopz-phi6 | \nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n return all(letter in sentence for letter in \'abcdefghijklmnopqrstuvwxyz\')\n\n | Lopkopz | NORMAL | 2021-06-04T11:52:02.133377+00:00 | 2021-06-04T11:52:02.133413+00:00 | 445 | false | ```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n return all(letter in sentence for letter in \'abcdefghijklmnopqrstuvwxyz\')\n```\nRuntime: 28 ms, **faster than 86.51%** of Python3 online submissions for Check if the Sentence Is Pangram.\nMemory Usage: 14 MB, **less than 91.22%** of Python3 online submissions for Check if the Sentence Is Pangram. | 6 | 1 | ['Python'] | 3 |
check-if-the-sentence-is-pangram | java beginner friendly || constant space | java-beginner-friendly-constant-space-by-pfep | Given constraint :\nsentence consists of lowercase English letters.\nIdea is to make a 26 size array (representing a to z ) and mark the presence of character i | himanshuchhikara | NORMAL | 2021-04-18T04:48:12.417482+00:00 | 2021-04-18T04:49:08.583175+00:00 | 466 | false | **Given constraint :**\n`sentence consists of lowercase English letters.`\nIdea is to make a 26 size array (representing a to z ) and mark the presence of character in it.\n\n**CODE:**\n```\n public boolean checkIfPangram(String sentence) {\n boolean[] arr=new boolean[26];\n for(char ch:sentence.toCharArray()){\n int idx=(int)(ch-\'a\');\n arr[idx]=true;\n }\n \n for(boolean val:arr){\n if(!val) return false;\n }\n return true;\n }\n```\n\n**Complexity:**\n`Time:O(n) and Space:O(1) [ constant space]`\n\nPlease **UPVOTE** if found it helpful :). Feel free to reach out to me or comment down if you have any doubt. | 6 | 1 | ['Java'] | 1 |
check-if-the-sentence-is-pangram | [Java/Python 3] Two codes: Count the chars in Sentence. | javapython-3-two-codes-count-the-chars-i-211b | Method 1\n\nJava\n\njava\n public boolean checkIfPangram(String sentence) {\n int[] cnt = new int[26];\n for (int i = 0; i < sentence.length(); | rock | NORMAL | 2021-04-18T04:06:54.875877+00:00 | 2021-04-18T17:14:19.409630+00:00 | 539 | false | **Method 1**\n\n**Java**\n\n```java\n public boolean checkIfPangram(String sentence) {\n int[] cnt = new int[26];\n for (int i = 0; i < sentence.length(); ++i) {\n ++cnt[sentence.charAt(i) - \'a\'];\n }\n for (int i = 0; i < 26; ++i) {\n if (cnt[i] == 0) {\n return false;\n }\n }\n return true;\n }\n```\nMake the above to 1 pass as follows:\n\n```java\n public boolean checkIfPangram(String sentence) {\n int[] cnt = new int[26];\n for (int i = 0, pan = 0; i < sentence.length(); ++i) {\n if (++cnt[sentence.charAt(i) - \'a\'] == 1 && ++pan == 26) {\n return true;\n }\n }\n return false;\n }\n```\n\n----\n\n**Python 3**\n```python\n def checkIfPangram(self, sentence: str) -> bool:\n return len(Counter(sentence)) == 26\n```\n\n----\n\n**Method 2: Bit Manipulation** -- credit to **@KenpachiZaraki1**.\n\n```java\n public boolean checkIfPangram(String sentence) {\n for (int i = 0, cnt = 0, pan = (1 << 26) - 1; i < sentence.length(); ++i) {\n cnt |= 1 << sentence.charAt(i) - \'a\';\n if (cnt == pan) {\n return true;\n }\n }\n return false;\n }\n```\n```python\n def checkIfPangram(self, sentence: str) -> bool:\n cnt, pan = 0, (1 << 26) - 1\n for c in sentence:\n cnt |= 1 << ord(c) - ord(\'a\')\n if cnt == pan:\n return True\n return False\n```\nIn case you are interested in one liner:\n```java\n public boolean checkIfPangram(String sentence) {\n return sentence.chars().map(i -> 1 << i - \'a\').reduce(0, (a, b) -> a | b) == (1 << 26) - 1;\n }\n```\n```python\n def checkIfPangram(self, sentence: str) -> bool:\n return functools.reduce(operator.ior, map(lambda c: 1 << ord(c) - ord(\'a\'), sentence)) == (1 << 26) - 1\n```\n**Analysis:**\n\nTime: `O(n)`, space: `O(1)`, where `n = sentence.length()`. | 6 | 0 | [] | 2 |
check-if-the-sentence-is-pangram | "Simple" ahh solution | simple-ahh-solution-by-anaghabharadwaj-b1en | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nTo check if a sentence | AnaghaBharadwaj | NORMAL | 2024-11-04T21:40:33.221965+00:00 | 2024-11-04T21:40:33.222011+00:00 | 755 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTo check if a sentence is a pangram, initialize a HashSet to store unique characters from the input. Iterate through each character in the sentence, adding it to the set. After the loop, if the set size is 26 (indicating every letter in the alphabet is present),return true; otherwise, false.\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n HashSet<Character> set = new HashSet<>();\n for(char c:sentence.toCharArray()){\n set.add(c);\n }\n return set.size()==26;\n }\n}\n``` | 5 | 0 | ['Java'] | 2 |
check-if-the-sentence-is-pangram | Simple JAVA Solution for beginners. 0ms. Beats 100%. | simple-java-solution-for-beginners-0ms-b-g4cm | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | sohaebAhmed | NORMAL | 2023-05-25T10:07:06.493287+00:00 | 2023-05-25T10:07:06.493342+00:00 | 579 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n for(char i = \'a\'; i <= \'z\'; i++) {\n if(sentence.indexOf(i) < 0) {\n return false;\n }\n }\n return true; \n }\n}\n``` | 5 | 0 | ['Hash Table', 'String', 'Java'] | 0 |
check-if-the-sentence-is-pangram | Java Basic and Simple logic, 0ms 100% faster, 40.6 MB beats 76% in memory Clean Code | java-basic-and-simple-logic-0ms-100-fast-ug9v | Intuition\nRun a loop over letter a - z and check whether each char occurs in the String\n\n# Approach\nIterate over 26 available alphabets and check whether we | thisisgmr | NORMAL | 2023-05-01T07:50:39.160736+00:00 | 2023-07-12T14:49:43.388306+00:00 | 641 | false | # Intuition\nRun a loop over letter a - z and check whether each char occurs in the String\n\n# Approach\nIterate over 26 available alphabets and check whether we have the character in the String.\n\n# Complexity\n- Time complexity:\nO(1). Instead of running over every character in the string which can range from 0 to 1000, we can run over 26 alphabets. \n\n- Space complexity:\nUse byte type to declare the iterator variable since we need numbers from 97 to 122 inclusive. Using byte will consume 1 byte where int consumes 4 bytes of memory.\n\n\n# Code\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n for( byte i = 97;i<=122;i++ ){\n if( sentence.indexOf( i ) == -1 ){\n return false;\n }\n }\n return true;\n }\n}\n``` | 5 | 0 | ['String', 'Java'] | 0 |
check-if-the-sentence-is-pangram | Easy and Simple- Java Solution using Arrays | easy-and-simple-java-solution-using-arra-yi2h | \nclass Solution {\n public boolean checkIfPangram(String sentence) {\n //declare a array to maintain every char occurance\n int a[]=new int[26 | dhirenojha01 | NORMAL | 2022-10-17T06:28:01.360992+00:00 | 2022-10-17T06:28:01.361030+00:00 | 988 | false | ```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n //declare a array to maintain every char occurance\n int a[]=new int[26];\n //traverse String\n for(int i=0;i<sentence.length();i++)\n {\n int ch;\n ch=sentence.charAt(i);\n if(a[ch-97]==1)\n continue;\n else\n a[ch-97]=1;\n }\n //traverse the Array to check for every char occurance \n for(int i=0;i<a.length;i++)\n {\n if(a[i]!=1)\n return false;\n }\n return true;\n }\n}\n``` | 5 | 0 | ['Array', 'Java'] | 2 |
check-if-the-sentence-is-pangram | 🗓️ Daily LeetCoding Challenge October, Day 17 | daily-leetcoding-challenge-october-day-1-9asu | This problem is the Daily LeetCoding Challenge for October, Day 17. Feel free to share anything related to this problem here! You can ask questions, discuss wha | leetcode | OFFICIAL | 2022-10-17T00:00:14.369831+00:00 | 2022-10-17T00:00:14.369906+00:00 | 2,229 | false | This problem is the Daily LeetCoding Challenge for October, Day 17.
Feel free to share anything related to this problem here!
You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made!
---
If you'd like to share a detailed solution to the problem, please create a new post in the discuss section and provide
- **Detailed Explanations**: Describe the algorithm you used to solve this problem. Include any insights you used to solve this problem.
- **Images** that help explain the algorithm.
- **Language and Code** you used to pass the problem.
- **Time and Space complexity analysis**.
---
**📌 Do you want to learn the problem thoroughly?**
Read [**⭐ LeetCode Official Solution⭐**](https://leetcode.com/problems/check-if-the-sentence-is-pangram/solution) to learn the 3 approaches to the problem with detailed explanations to the algorithms, codes, and complexity analysis.
<details>
<summary> Spoiler Alert! We'll explain this 0 approach in the official solution</summary>
</details>
If you're new to Daily LeetCoding Challenge, [**check out this post**](https://leetcode.com/discuss/general-discussion/655704/)!
---
<br>
<p align="center">
<a href="https://leetcode.com/subscribe/?ref=ex_dc" target="_blank">
<img src="https://assets.leetcode.com/static_assets/marketing/daily_leetcoding_banner.png" width="560px" />
</a>
</p>
<br> | 5 | 0 | [] | 75 |
check-if-the-sentence-is-pangram | Begineer Friendly | begineer-friendly-by-diljotsingh04-koxr | \nclass Solution {\n public boolean checkIfPangram(String sentence) {\n int[] arr = new int[26];\n \n // checks the frequency of the alp | diljotsingh04 | NORMAL | 2022-09-28T10:17:42.684899+00:00 | 2022-09-28T10:17:42.684941+00:00 | 1,146 | false | ```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n int[] arr = new int[26];\n \n // checks the frequency of the alphabets\n for(var i: sentence.toCharArray()){\n arr[i - \'a\']++;\n }\n \n // checks if any of the arr index contains zero\n for(var i: arr){\n if(i == 0)\n return false;\n }\n \n return true;\n }\n}\n``` | 5 | 0 | ['String', 'Java'] | 0 |
check-if-the-sentence-is-pangram | [0ms] Java Easy Solution w/ Array && .indexOf | 0ms-java-easy-solution-w-array-indexof-b-573q | \nclass Solution {\n public boolean checkIfPangram(String sentence) {\n if (sentence.length() < 26) {\n return false;\n }\n\n | RexRK | NORMAL | 2022-09-20T14:54:23.717885+00:00 | 2022-09-20T14:54:23.717927+00:00 | 284 | false | ```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n if (sentence.length() < 26) {\n return false;\n }\n\n int[] tracer = new int[26]; //For Storing Index of a-z charecters from sentence;\n char alpha = \'a\'; \n for (int i = 0; i < tracer.length; i++) {\n tracer[i] = sentence.indexOf(alpha); //assigning index of alphabets\n \n if (tracer[i] == -1) {\n return false; \n //if any alphabet isn\'t present -1 will be stored in array && return with false value;\n }\n alpha++; //else increment of alphabet\n\n }\n return true; //there isn\'t any -1 stored in array so every alphabet will be present\n }\n}\n``` | 5 | 0 | ['Java'] | 0 |
check-if-the-sentence-is-pangram | Beginner friendly [Java/JavaScript/Python] Solution | beginner-friendly-javajavascriptpython-s-uf2s | Python\n\nclass Solution(object):\n def checkIfPangram(self, sentence):\n return len(set(sentence)) == 26\n\nJavaScript\n\nvar checkIfPangram = functi | HimanshuBhoir | NORMAL | 2022-01-12T03:07:44.095765+00:00 | 2022-10-17T07:36:56.830092+00:00 | 754 | false | **Python**\n```\nclass Solution(object):\n def checkIfPangram(self, sentence):\n return len(set(sentence)) == 26\n```\n**JavaScript**\n```\nvar checkIfPangram = function(sentence) {\n return new Set(sentence).size == 26;\n};\n```\n**Java**\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n Set set = new HashSet<>();\n for(char c : sentence.toCharArray()) set.add(c);\n return set.size() == 26;\n }\n}\n``` | 5 | 0 | ['Python', 'Java', 'JavaScript'] | 3 |
check-if-the-sentence-is-pangram | Easy Java Solution | easy-java-solution-by-zcyuzz-ssnq | \nclass Solution {\n public boolean checkIfPangram(String sentence) {\n int[] count = new int[26];\n for (char ch : sentence.toCharArray()) {\n | zcyuzz | NORMAL | 2021-08-24T22:23:30.593193+00:00 | 2021-08-24T22:23:30.593229+00:00 | 483 | false | ```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n int[] count = new int[26];\n for (char ch : sentence.toCharArray()) {\n count[ch - \'a\']++;\n }\n for (int i : count) {\n if (i == 0) return false;\n }\n return true;\n }\n}\nfeel free to ask any question\n``` | 5 | 0 | ['Java'] | 4 |
check-if-the-sentence-is-pangram | simple cpp solution | simple-cpp-solution-by-ashuborla-tj50 | bool checkIfPangram(string sentence) {\n \n sets;\n for(int i=0;i<sentence.size();i++)\n s.insert(sentence[i]);\n int n=s | ashuborla | NORMAL | 2021-05-15T17:38:08.834076+00:00 | 2021-05-15T17:38:08.834119+00:00 | 167 | false | bool checkIfPangram(string sentence) {\n \n set<char>s;\n for(int i=0;i<sentence.size();i++)\n s.insert(sentence[i]);\n int n=s.size();\n if(n==26)\n return true;\n else\n return false;\n \n } | 5 | 1 | [] | 4 |
check-if-the-sentence-is-pangram | Simple Solution and easy to understand || [ Java] ✅✅ | simple-solution-and-easy-to-understand-j-5d78 | Intuition\n##### Store every charecter at string in HashMap and check at all english charecters if it exist or not\n\n# Approach\n### Step 1 : \n### Looping at | elocklymuhamed | NORMAL | 2024-04-15T11:34:08.576367+00:00 | 2024-04-17T13:02:36.647854+00:00 | 467 | false | # Intuition\n##### Store every charecter at string in HashMap and check at all english charecters if it exist or not\n\n# Approach\n### Step 1 : \n### Looping at all sentence charecter and store it at HashMap we used HashMap as it give us time O(1) when check the existence of the cherecter \n```\nmap.containsKey(chIndex)\n```\n### Step 2 : Looping at all 26 english charecters and check the existence of the charecter in the HashMap by the unique ASCII Code of each charecter . We Know small english charecter start with 97 at ASCII Code system\n##### Finally : If you like the method of solution and explanation, do not hesitate to vote up to encourage me to solve more problems and solve them in better ways.\n# Complexity\n- Time complexity: \nO(n) where n is the length of alphabet english characters\n- Space complexity:\nO(n) where n is the length of charecters at the Given String\n# Code\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n HashMap<Integer, Character> map = new HashMap<Integer, Character>();\n\n for (int i = 0; i < sentence.length(); i++) {\n int chIndex = (int) (sentence.charAt(i));\n if (!map.containsKey(chIndex)) {\n map.put( chIndex, sentence.charAt(i));\n }\n }\n for (int i = 0; i < 26; i++) {\n \n if (!map.containsKey(97 + i)) {\n return false;\n }\n }\n return true;\n }\n}\n\n```\n\n | 4 | 0 | ['Java'] | 0 |
check-if-the-sentence-is-pangram | Beats 100.00% of user || Step by Step Explain || Easy to Understand || Using Hashtable || | beats-10000-of-user-step-by-step-explain-2jbq | Abhiraj Pratap Singh \n\n---\n\n# if you like the solution please UPVOTE it .....\n\n---\n\n# Intuition\n Describe your first thoughts on how to solve this prob | abhirajpratapsingh | NORMAL | 2024-02-01T16:18:52.812722+00:00 | 2024-02-01T16:18:52.812753+00:00 | 139 | false | # Abhiraj Pratap Singh \n\n---\n\n# if you like the solution please UPVOTE it .....\n\n---\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- The code checks whether the input string sentence is a pangram or not.\n---\n\n\n\n---\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Initialize an array arr of size 26 (assuming only lowercase English letters) with all elements set to 0.\n- Iterate through each character in the sentence.\n- Increment the corresponding element in the array for each encountered character.\n- Check if any element in the array is still 0, indicating a missing letter in the sentence.\n- If any element is 0, return false; otherwise, return true.\n\n---\n\n# Complexity\n\n- **Time complexity:** O(n), where n is the length of the input string sentence.\n\n- **Space complexity:** O(1) since the size of the array arr is fixed at 26, and it does not depend on the input size.\n\n---\n# Code\n```\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) \n {\n int arr[26] = { 0 } ;\n for( int i=0 ; i < sentence.length() ; i++ )\n arr[ sentence[i]-\'a\' ]++;\n for( int i=0 ; i < 26 ; i++ )\n {\n if( arr[i] == 0 )\n return false ;\n } \n return true;\n }\n};\n```\n\n---\n# if you like the solution please UPVOTE it .....\n\n---\n\n\n\n---\n | 4 | 0 | ['Hash Table', 'String', 'String Matching', 'C++'] | 0 |
check-if-the-sentence-is-pangram | Easy and simple approach | easy-and-simple-approach-by-kanishakpran-gsoc | Intuition\nThe goal is to check if the given string s contains all the letters of the alphabet at least once, making it a pangram. The provided code appears to | kanishakpranjal | NORMAL | 2024-01-16T16:56:32.955211+00:00 | 2024-01-16T16:56:32.955243+00:00 | 326 | false | # Intuition\nThe goal is to check if the given string `s` contains all the letters of the alphabet at least once, making it a pangram. The provided code appears to iterate through the alphabet and checks if each letter is present in the input string. The count of letters found is then compared to the total number of letters in the alphabet.\n\n# Approach\nThe approach taken in the code is to iterate through each letter of the alphabet and check if it exists in the input string. The count of letters found is then compared to the total number of letters in the alphabet. If the count is equal to or greater than 26 (the total number of letters in the English alphabet), the function returns true, indicating that the input string is a pangram.\n\n# Complexity\n- Time complexity: O(n * m), where n is the length of the input string and m is the length of the alphabet. The `contains` method takes O(n) time in the worst case, and it is called for each letter in the alphabet.\n- Space complexity: O(1), as the space used is constant (for the alphabet string and integer variables).\n\n# Code\n```java\nclass Solution {\n public boolean checkIfPangram(String s) {\n int count = 0;\n String alphabet = "qwertyuiopasdfghjklzxcvbnm";\n\n for (int i = 0; i < alphabet.length(); i++) {\n if (s.contains(String.valueOf(alphabet.charAt(i)))) {\n count++;\n }\n }\n \n return count >= 26;\n }\n}\n``` | 4 | 0 | ['Java'] | 0 |
check-if-the-sentence-is-pangram | Easy Solution for Beginners in java | easy-solution-for-beginners-in-java-by-t-1p5k | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | thehighpriestess | NORMAL | 2023-09-07T00:24:08.199737+00:00 | 2023-09-07T00:24:08.199756+00:00 | 469 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n boolean answer = false;\n\t\t\tfor(char alpha = \'a\' ; alpha<=\'z\' ; alpha++) {\n\t\t \tif(sentence.indexOf(alpha) == -1) {\n\t\t \t\tanswer= false;\n\t\t \t\tbreak;\n\t\t \t}else {\n\t\t \t\tanswer= true;\n\t\t \t}\n\t\t }\n\t\t return answer;\n }\n}\n``` | 4 | 0 | ['Java'] | 1 |
check-if-the-sentence-is-pangram | Easy Solution- Java and Python(0ms Runtime, Optimised) | easy-solution-java-and-python0ms-runtime-jebr | Code\njava []\n\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n for (int i=97;i<=122;i++)\n {\n if(sentence.i | phalakbh | NORMAL | 2023-07-31T18:21:00.533982+00:00 | 2023-07-31T18:21:00.534025+00:00 | 231 | false | # Code\n```java []\n\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n for (int i=97;i<=122;i++)\n {\n if(sentence.indexOf((char)i)<0)\n {\n return false;\n }\n }\n return true;\n }\n}\n```\n```python []\nclass Solution(object):\n def checkIfPangram(self, sentence):\n for num in range(97,123):\n if chr(num) not in sentence:\n return False\n return True;\n```\n\n | 4 | 0 | ['String', 'Python', 'Java'] | 1 |
check-if-the-sentence-is-pangram | Easy and highly optimized solution Java and Python ||Beats 100% Runtime|| | easy-and-highly-optimized-solution-java-83tfr | Java []\n public boolean checkIfPangram(String sentence) {\n for (int i=97;i<=122;i++)\n {\n if(sentence.indexOf((char)i)<0)\n | _veer_singh04_ | NORMAL | 2023-07-31T18:18:48.706662+00:00 | 2023-07-31T18:18:48.706701+00:00 | 313 | false | ```Java []\n public boolean checkIfPangram(String sentence) {\n for (int i=97;i<=122;i++)\n {\n if(sentence.indexOf((char)i)<0)\n {\n return false;\n }\n }\n return true;\n }\n}\n```\n```python []\nclass Solution(object):\n def checkIfPangram(self, sentence):\n for num in range(97,123):\n if chr(num) not in sentence:\n return False\n \xA0\xA0\xA0\xA0return\xA0True\n``` | 4 | 0 | ['Python', 'Java'] | 1 |
check-if-the-sentence-is-pangram | Beats - 100% || Simple - Easy to Understand Solution | beats-100-simple-easy-to-understand-solu-zq6e | \n\n# Code\n\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n for(char i = \'a\'; i<=\'z\'; i++){\n if(sentence.index | tauqueeralam42 | NORMAL | 2023-07-17T08:46:50.590267+00:00 | 2023-07-17T08:46:50.590295+00:00 | 298 | false | \n\n# Code\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n for(char i = \'a\'; i<=\'z\'; i++){\n if(sentence.indexOf(i)<0)\n return false;\n }\n return true;\n }\n}\n``` | 4 | 0 | ['Hash Table', 'String', 'C++', 'Java'] | 0 |
check-if-the-sentence-is-pangram | JAVA | 100 % | 0 ms | java-100-0-ms-by-firdavs06-l69v | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Firdavs06 | NORMAL | 2023-02-27T07:35:23.785207+00:00 | 2023-02-27T07:35:23.785232+00:00 | 155 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n if(sentence.length() < 26)\n return false;\n for(char c = \'a\'; c <= \'z\'; c++){\n if(!sentence.contains(String.valueOf(c)))\n return false;\n }\n return true;\n }\n}\n``` | 4 | 0 | ['Java'] | 1 |
check-if-the-sentence-is-pangram | JS/TS one-liner using Set || Beats 94% | jsts-one-liner-using-set-beats-94-by-cim-yitn | Intuition\nJavascript\'s set contains only unique values, and total of lowercase english alphabet is 26.\n\n# Approach\n1. We split the characters in the senten | cimbraien | NORMAL | 2023-02-15T14:11:32.276233+00:00 | 2023-02-15T14:13:37.905429+00:00 | 353 | false | # Intuition\nJavascript\'s set contains only unique values, and total of lowercase english alphabet is 26.\n\n# Approach\n1. We split the characters in the sentence into an array.\n2. Convert the array into a set.\n3. Check if the set\'s size is equal to 26.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n# Code\n```\nfunction checkIfPangram(sentence: string): boolean {\n return new Set(sentence.split("")).size == 26;\n};\n``` | 4 | 0 | ['TypeScript', 'JavaScript'] | 1 |
check-if-the-sentence-is-pangram | O(1) Java Solution Easy to Understand. | o1-java-solution-easy-to-understand-by-j-9l3v | \n# Complexity\n- Time complexity:\nO(1)\n\n- Space complexity:\nO(N)\n\n# Code\n\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n\n | jaiyadav | NORMAL | 2023-01-01T04:51:53.759686+00:00 | 2023-01-01T04:51:53.759737+00:00 | 703 | false | \n# Complexity\n- Time complexity:\nO(1)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n\n Character[] charArray = \n sentence.chars().mapToObj(c -> (char)c).toArray(Character[]::new); //don\'t get confused about it because i also copied it from stack overflow , this function basically create the Character[] type array from the string.\n\n List<Character>check=Arrays.asList(charArray);//now we convert the Character type of array into List<Character>\n\n Set<Character>st=new HashSet<>(check);//now we store that list into set\n \n return st.size()==26;//as we all know that the set contains unique character so it is confirmed that if the set size is 26 which means that set contains all the characters from a to z.\n\n }\n}\n``` | 4 | 0 | ['Hash Table', 'String', 'Java'] | 0 |
check-if-the-sentence-is-pangram | JAVA || SET || 2 LINE CODE | java-set-2-line-code-by-sharforaz_rahman-nipn | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nturn string into character array and then put those values into SET and a | sharforaz_rahman | NORMAL | 2022-11-23T12:07:20.982407+00:00 | 2023-05-09T13:16:02.310283+00:00 | 50 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nturn string into **character array** and then put those values into **SET** and as we know that SET doesn\'t contain duplicate values, so after putting values in set, if the **size of set is less than 26,** then it is false, because english alpahbeth has 26 letters.\n\n# Code\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n char[] ch = sentence.toCharArray();\n Set<Character> s = new HashSet<>();\n for(char c:ch) s.add(c);\n return set.size() >= 26;\n \n }\n}\n``` | 4 | 0 | ['Java'] | 0 |
check-if-the-sentence-is-pangram | ✅ [Python/Rust] just one-liners using hashset... (with detailed comments) | pythonrust-just-one-liners-using-hashset-uevo | IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.\n\nPython. This solution employs a simple one-liner using set. It demonstrated 28 ms runtime (97.56%) and used 13.8 MB | stanislav-iablokov | NORMAL | 2022-10-17T12:41:01.157644+00:00 | 2022-10-23T12:35:55.917863+00:00 | 369 | false | **IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n\n**Python.** This [**solution**](https://leetcode.com/submissions/detail/824403614/) employs a simple one-liner using *set*. It demonstrated **28 ms runtime (97.56%)** and used **13.8 MB memory (95.55%)**. Time complexity is linear: **O(n)**. Space complexity is constant: **O(1)**. \n```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n # in Python, a set can automatically be constructed\n # from iterables such as strings, lists, ...\n return len(set(sentence)) == 26\n```\n\n**Rust.** This [**solution**](https://leetcode.com/submissions/detail/824403614/) employs a simple one-liner using *HashSet*. It demonstrated **0 ms runtime (100.00%)** and used **2.2 MB memory (26.92%)**. Time complexity is linear: **O(n)**. Space complexity is constant: **O(1)**. \n```\nuse std::collections::HashSet;\n\nimpl Solution \n{\n pub fn check_if_pangram(sentence: String) -> bool \n {\n // in Rust, a HashSet can automatically be\n // built (collected) from an iterator \n sentence.chars().collect::<HashSet<char>>().len() == 26\n }\n}\n``` | 4 | 0 | ['Python', 'Rust'] | 0 |
check-if-the-sentence-is-pangram | Daily LeetCoding Challenge October, Day 17 | daily-leetcoding-challenge-october-day-1-cr7l | The approach followed here is very simple. We store the frequency of charecters in an array or a vector. Then we simply traverse through the array or vector to | deleted_user | NORMAL | 2022-10-17T06:03:08.121533+00:00 | 2022-10-17T06:03:08.121595+00:00 | 2,878 | false | The approach followed here is very simple. We store the frequency of charecters in an array or a vector. Then we simply traverse through the array or vector to check if element is present at least once.\n\n```\nclass Solution {\npublic:\n bool checkIfPangram(string sentence)\n {\n int start=\'a\',end=\'z\';\n vector<int> a(26,0);\n for(char ch:sentence)\n {\n if(!(ch>=start && ch<=end))\n return false;\n a[ch-\'a\']++;\n }\n for(int i:a)\n if(i<1)\n return false;\n return true;\n }\n};\n``` | 4 | 0 | ['Array', 'String', 'C'] | 3 |
check-if-the-sentence-is-pangram | 100% Faster Solution with 0 ms | 100-faster-solution-with-0-ms-by-prayash-u3sy | \nI come with the solution to this question with three different approach:\nFirst Approach:\nUsing String \nclass Solution {\n public boolean checkIfPangram( | PRAYASH_GUPTA | NORMAL | 2022-08-22T04:52:12.574384+00:00 | 2022-08-22T04:52:12.574423+00:00 | 214 | false | ```\nI come with the solution to this question with three different approach:\nFirst Approach:\nUsing String \nclass Solution {\n public boolean checkIfPangram(String sentence) {\n if(sentence.length()<26){\n return false;\n }\n String s="abcdefghijklmnopqrstuvwxyz";\n for(int i=0;i<s.length();i++){\n if(sentence.indexOf(s.charAt(i))==-1){\n return false;\n }\n }\n return true;\n}\n}\n\n```\n```\nSecond Approach:\nUsing Array\n\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n int arr[]=new int[26];\n for(char x:sentence.toCharArray()){\n arr[x-\'a\']++;\n }\n for(int i=0;i<26;i++){\n if(arr[i]==0){\n return false;\n }\n }\n return true;\n }\n}\n```\n```\nThird Approach:\nUsing HashSet\n\n\n\n\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n HashSet<Character> h = new HashSet<>();\n for(char x:sentence.toCharArray()){\n h.add(x);\n }\n if(h.size()==26){\n return true;\n }\n return false;\n }\n}\n``` | 4 | 0 | ['Array', 'String', 'Java'] | 0 |
check-if-the-sentence-is-pangram | Python easy solution using dictionary | python-easy-solution-using-dictionary-by-sa5e | ```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n appear = {}\n for i in sentence:\n if i not in appear:\n | abdulhamid-egamberdiyev | NORMAL | 2022-03-21T05:17:06.394327+00:00 | 2022-03-21T05:17:06.394370+00:00 | 216 | false | ```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n appear = {}\n for i in sentence:\n if i not in appear:\n appear[i] = 1\n else:\n appear[i] += 1\n if len(appear) == 26:\n return True\n return False | 4 | 0 | ['Hash Table', 'Python'] | 0 |
check-if-the-sentence-is-pangram | Java || 3 Line Solution || 88% Faster || Easy to understand | java-3-line-solution-88-faster-easy-to-u-x0ch | \nclass Solution {\n public boolean checkIfPangram(String sentence) {\n for(char c = \'a\'; c <= \'z\'; c++)\n if(!sentence.contains(""+c) | arpit2304 | NORMAL | 2022-02-16T14:48:44.728603+00:00 | 2022-02-16T14:48:44.728636+00:00 | 219 | false | ```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n for(char c = \'a\'; c <= \'z\'; c++)\n if(!sentence.contains(""+c))return false;\n return true;\n }\n}\n```\nPlease **UPVOTE** if you find this solution helpful.\nThanks : ) | 4 | 0 | ['Java'] | 1 |
check-if-the-sentence-is-pangram | Short JavaScript Solution. | short-javascript-solution-by-himanshubho-0mu5 | Time Complexity : O(n)\njavascript []\nvar checkIfPangram = function(sentence) {\n return new Set(sentence.split("")).size == 26;\n};\n\n | HimanshuBhoir | NORMAL | 2022-01-12T03:04:24.278438+00:00 | 2023-01-09T06:24:23.433013+00:00 | 577 | false | **Time Complexity : O(n)**\n```javascript []\nvar checkIfPangram = function(sentence) {\n return new Set(sentence.split("")).size == 26;\n};\n```\n | 4 | 0 | ['JavaScript'] | 2 |
check-if-the-sentence-is-pangram | Python one line simple solution | python-one-line-simple-solution-by-tovam-ueqc | Python :\n\n\ndef checkIfPangram(self, sentence: str) -> bool:\n\treturn set(sentence) == set(list(string.ascii_lowercase)) \n\n\nLike it ? please upvote ! | TovAm | NORMAL | 2021-11-06T23:47:24.323981+00:00 | 2021-11-06T23:48:21.180314+00:00 | 158 | false | **Python :**\n\n```\ndef checkIfPangram(self, sentence: str) -> bool:\n\treturn set(sentence) == set(list(string.ascii_lowercase)) \n```\n\n**Like it ? please upvote !** | 4 | 0 | ['Python', 'Python3'] | 1 |
check-if-the-sentence-is-pangram | Python solution | python-solution-by-saura_v-ahtw | \nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n return len(set(sentence)) == 26\n | Saura_v | NORMAL | 2021-08-16T15:21:57.203534+00:00 | 2021-08-16T15:21:57.203582+00:00 | 184 | false | ```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n return len(set(sentence)) == 26\n``` | 4 | 0 | ['Ordered Set', 'Python'] | 0 |
check-if-the-sentence-is-pangram | Python3 faster than 86% | python3-faster-than-86-by-truejacobg-4dns | \nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n if len(set(sentence.lower())) == 26:\n return True\n return F | TrueJacobG | NORMAL | 2021-06-08T12:23:50.209024+00:00 | 2021-06-08T12:23:50.209091+00:00 | 151 | false | ```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n if len(set(sentence.lower())) == 26:\n return True\n return False\n``` | 4 | 0 | [] | 1 |
check-if-the-sentence-is-pangram | C# Simple One liner | c-simple-one-liner-by-hbti_ankit1994-6erw | \npublic class Solution {\n public bool CheckIfPangram(string s) {\n return ((new HashSet<char>(s)).Count == 26); \n}\n\n\nAnother Approach:\n\np | hbti_ankit1994 | NORMAL | 2021-05-12T16:45:15.719737+00:00 | 2021-05-13T07:54:17.644611+00:00 | 152 | false | ```\npublic class Solution {\n public bool CheckIfPangram(string s) {\n return ((new HashSet<char>(s)).Count == 26); \n}\n```\n\nAnother Approach:\n```\npublic class Solution {\n public bool CheckIfPangram(string s) {\n return ((s.ToCharArray()).Distinct().Count()) == 26;\n }\n}\n```\n\n\nAnother Approach:\n```\npublic class Solution {\n public bool CheckIfPangram(string s) {\n for(char ch = \'a\'; ch <= \'z\'; ch++)\n if(!s.Contains(ch))\n return false;\n return true;\n }\n}\n```\n\nAnother Approach:\n```\npublic class Solution {\n public bool CheckIfPangram(string s) {\n int[] count = new int[26];\n foreach(char ch in s)\n count[ch-\'a\']++;\n for(int i=0; i<26; i++)\n if(count[i] == 0)\n return false;\n return true;\n }\n}\n``` | 4 | 0 | [] | 2 |
check-if-the-sentence-is-pangram | [C++] Simple Solution || O(N) || Easy Understanding | c-simple-solution-on-easy-understanding-ucztf | C++ solution:\n\nclass Solution {\npublic:\n bool checkIfPangram(string s) {\n vector<int>vis(26,0);\n int count=0;\n for(auto i:s)\n | millenniumdart09 | NORMAL | 2021-04-18T11:10:37.113546+00:00 | 2021-04-18T11:10:37.113581+00:00 | 344 | false | **C++ solution:**\n```\nclass Solution {\npublic:\n bool checkIfPangram(string s) {\n vector<int>vis(26,0);\n int count=0;\n for(auto i:s)\n {\n if(!vis[i-\'a\'])\n {\n vis[i-\'a\']=1;\n count++;\n }\n }\n if(count>=26)\n return 1;\n return 0;\n \n }\n};\n``` | 4 | 1 | ['C'] | 0 |
check-if-the-sentence-is-pangram | Rust solution | rust-solution-by-bigmih-xp8w | \nimpl Solution {\n pub fn check_if_pangram(sentence: String) -> bool {\n sentence\n .as_bytes()\n .iter()\n .fold([f | BigMih | NORMAL | 2021-04-18T08:30:50.047607+00:00 | 2021-04-25T11:52:31.671418+00:00 | 214 | false | ```\nimpl Solution {\n pub fn check_if_pangram(sentence: String) -> bool {\n sentence\n .as_bytes()\n .iter()\n .fold([false; 26], |mut count_arr, &x| {\n count_arr[(x - b\'a\') as usize] = true;\n count_arr\n })\n .iter()\n .all(|&x| x)\n }\n}\n``` | 4 | 0 | ['Array', 'Rust'] | 2 |
check-if-the-sentence-is-pangram | Simple Python Solution | simple-python-solution-by-lokeshsk1-tqjh | \nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n\t\treturn len(set(sentence))==26\n\n\n\nclass Solution:\n def checkIfPangram(self, | lokeshsk1 | NORMAL | 2021-04-18T04:10:28.817998+00:00 | 2021-04-18T04:12:01.967596+00:00 | 231 | false | ```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n\t\treturn len(set(sentence))==26\n```\n\n```\nclass Solution:\n def checkIfPangram(self, sentence: str) -> bool:\n for i in range(97,123):\n if chr(i) not in sentence:\n return False\n return True\n``` | 4 | 1 | [] | 2 |
check-if-the-sentence-is-pangram | Simple unordered map solution || c++ | simple-unordered-map-solution-c-by-ujjwa-tdkw | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | ujjwalkathait | NORMAL | 2024-01-21T18:25:50.630218+00:00 | 2024-01-21T18:25:50.630250+00:00 | 74 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O{n}\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n if(sentence.size() < 26)\n return false;\n \n unordered_map<char, int> mp;\n\n for(int i=0; i<sentence.size(); i++){\n mp[sentence[i]]++;\n }\n if(mp.size() == 26) return 1;\n return 0;\n }\n};\n``` | 3 | 0 | ['Array', 'Hash Table', 'C++'] | 0 |
check-if-the-sentence-is-pangram | Hash Map Solution (with step by step explanation) | hash-map-solution-with-step-by-step-expl-50ir | Intuition\nFor this problem we would use hashmap\n\n# Approach\nWe use hashmap for this problem to store all alphabet letter from input string, and then simply | alekseyvy | NORMAL | 2023-09-10T19:02:49.350875+00:00 | 2023-09-10T19:02:49.350896+00:00 | 173 | false | # Intuition\nFor this problem we would use hashmap\n\n# Approach\nWe use hashmap for this problem to store all alphabet letter from input string, and then simply check that size of our hashmap are equals to size of english alphabet.\n# Complexity\n- Time complexity:\nO(n) - we iterate only once to get all letters\n- Space complexity:\nO(1) - we create hashmap but we know that it can\'t grow more than 26, so it\'s constant from 0 to 26, but we can get n length sentience and this will not change size of hashmap\n# Code\n```\nclass Solution {\n public boolean checkIfPangram(String sentence) {\n // declare hashmap to store letters from sentience\n Map<Character, Integer> hash = new HashMap<>();\n // iterate over sentience:\n for(int i = 0; i < sentence.length(); i++) {\n // put letters into hashmap, since we dont neet to calculate specific number of letters we can just always set it to 1\n hash.put(sentence.charAt(i), 1);\n }\n // if hashmap is size of english alphabet return true, false otherwise\n return hash.size() == 26 ? true : false;\n }\n}\n``` | 3 | 0 | ['Hash Table', 'Java'] | 0 |
check-if-the-sentence-is-pangram | Damm Easyyyy | damm-easyyyy-by-hkd-k409 | Important\nPlease upvote before reading\n\n\n# Intuition\nRemember the alphabet u learnt in primary class\n\n# Approach\nSexy\n\n# Complexity\n- Time complexity | HKD_ | NORMAL | 2023-09-03T14:30:57.091056+00:00 | 2023-09-03T14:30:57.091086+00:00 | 264 | false | # Important\nPlease upvote before reading\n\n\n# Intuition\nRemember the alphabet u learnt in primary class\n\n# Approach\nSexy\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n public boolean checkIfPangram(String s) {\n int l=s.length();\n int i,a; char ch; int c=0;\n for(i=0;i<l;i++){\n ch=s.charAt(i);\n a=(int)ch;\n if(a>=97 && a<=122)\n { c++; s=s.replace(ch,\' \'); }\n } \n if(c==26)\n return true;\n else\n return false;\n }\n}\n``` | 3 | 0 | ['Java'] | 2 |
check-if-the-sentence-is-pangram | C# solution with explanation | Beats 100% of C# solutions | c-solution-with-explanation-beats-100-of-ouxy | Approach\nI just created a hashset of chars in the given string. Then checked every letter in English alphabet if it exists in the hashset using the letter\'s A | Muhammad-Diyor | NORMAL | 2023-08-05T14:27:19.554678+00:00 | 2023-08-07T05:15:08.337245+00:00 | 297 | false | # Approach\nI just created a hashset of chars in the given string. Then checked every letter in English alphabet if it exists in the hashset using the letter\'s ASCII code.\n\n# Runtime\nBeats 100% of solutions with C#\n\n\n# Code\n```\npublic class Solution {\n public bool CheckIfPangram(string sentence) {\n var hashSet = new HashSet<char>(sentence);\n for (int i = 97; i <= 122; i++)\n {\n if(!hashSet.Contains((char)i))\n return false;\n }\n\n return true;\n }\n}\n``` | 3 | 0 | ['C#'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.